Pagini recente » Cod sursa (job #2317280) | Cod sursa (job #2948706) | Cod sursa (job #1448619) | Cod sursa (job #975973) | Cod sursa (job #1752729)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
long long d[1000001];
int main()
{
long long m,n,i,x,y,first=999999999,maxx=0,s,last=-1;
fin>>m>>n;
for(i=1;i<=n;i++)
{
fin>>x>>y;
d[x]=max(d[x],y);
if(x<first)
first=x;
if(x>last)
last=x;
}
s=d[first];
for(i=first;i<=last;i++)
{
if(d[i]==0)s++;
else
{
s++;
if(s+d[i]>maxx)maxx=s+d[i];
if(s<d[i])s=d[i];
}
}
fout<<maxx;
return 0;
}