Pagini recente » Cod sursa (job #390953) | Monitorul de evaluare | Cod sursa (job #414740) | Cod sursa (job #2848849) | Cod sursa (job #1436639)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
struct strada
{
int st,lung;
};
bool cmp(strada x,strada y)
{
if(x.st<y.st)
return true;
else
return false;
}
strada v[1000001];
int main()
{
ifstream fin ("orase.in");
ofstream fout ("orase.out");
int m,n,i,max=-2000000000,max2=-2000000000,poz,aux;
fin>>m>>n;
for(i=1; i<=n; i++)
fin>>v[i].st>>v[i].lung;
sort(v+1,v+n+1,cmp);
for(i=1;i<=n;i++)
{
aux=v[i].st;
v[i].st=v[i].lung-v[i].st;
v[i].lung+=aux;
if(v[i].st>max)
{
max=v[i].st;
poz=i;
}
}
for(i=1;i<poz;i++)
{
if(max2<v[i].lung)
max2=v[i].lung;
}
for(i=poz+1;i<=n;i++)
if(max2<v[i].lung)
max2=v[i].lung;
fout<<max+max2;
return 0;
}