Mai intai trebuie sa te autentifici.
Cod sursa(job #1752732)
Utilizator | Data | 4 septembrie 2016 22:54:54 | |
---|---|---|---|
Problema | Orase | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.69 kb |
#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+1;i<=last;i++)
{
s++;
if(d[i]!=0)
{
if(s+d[i]>maxx)maxx=s+d[i];
if(s<d[i])s=d[i];
}
}
if(first==last)
fout<<0;
else
fout<<maxx;
return 0;
}