Pagini recente » Cod sursa (job #491088) | Cod sursa (job #3212616) | Cod sursa (job #1675608) | Cod sursa (job #621483) | Cod sursa (job #2142462)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
struct street_type
{
int poz,lung;
} v[50005];
bool cmp(street_type a,street_type b)
{
return a.poz<b.poz;
}
int main()
{
long long int sol=0;
int m,n;
in>>m>>n;
for(int i=1; i<=n; i++)
{
in>>v[i].poz>>v[i].lung;
}
sort(v+1,v+n+1,cmp);
int startl=v[1].lung;
int startpoz=v[1].poz;
for(int i=2; i<=n; i++)
{
int stopl=v[i].lung;
int stoppoz=v[i].poz;
if(startl+stopl+(stoppoz-startpoz)>sol)
sol=startl+stopl+(stoppoz-startpoz);
if(stopl>startl+stoppoz-startpoz)
{
startpoz=stoppoz;
startl=stopl;
}
}
out<<sol;
}