Pagini recente » Profil terrilyn5017 | Cod sursa (job #874032) | Cod sursa (job #598084) | Cod sursa (job #867158) | Cod sursa (job #1770246)
#include <fstream>
#include <algorithm>
#define nmax 50001
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
int m,n,i,rez,v[nmax];
pair < int , int > a[nmax];
int main()
{
fin>>n>>m;
for(i=1;i<=m;i++)
fin>>a[i].first>>a[i].second;
sort(a+1,a+m+1);
for(i=1;i<=m;i++)
{
if(a[i].first+a[i].second-a[i-1].first+v[i-1]>rez)
{
rez=a[i].first+a[i].second-a[i-1].first+v[i-1];
}
v[i]=max(v[i-1]+a[i].first-a[i-1].first,a[i].second);
}
fout<<rez;
return 0;
}