Pagini recente » Cod sursa (job #872048) | Cod sursa (job #1454672) | Cod sursa (job #1996210) | Cod sursa (job #834993) | Cod sursa (job #1734088)
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
struct str
{
int x,y;
}v[50000];
struct str_cmp
{
bool operator() (const str &x,const str &y)
{
return x.x<y.x;
}
};
int main()
{
int m,n;
int lmax=0,sol=0;
int i,j;
in>>m>>n;
for(i=1;i<=n;i++)
{
in>>v[i].x>>v[i].y;
}
sort(v+1,v+n+1,str_cmp());
lmax=v[1].y;
v[0].x=0;
for(i=2;i<=n;i++)
{
lmax=lmax+v[i].x-v[i-1].x;
if(lmax+v[i].y>sol)
{
sol=lmax+v[i].y;
}
if(lmax<v[i].y)
{
lmax=v[i].y;
}
}
out<<sol;
}