Pagini recente » Cod sursa (job #3277089) | Cod sursa (job #2216649) | Cod sursa (job #445638) | Cod sursa (job #2284759) | Cod sursa (job #2290780)
#include <fstream>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
int main()
{
int n,m,lm=0,dm=0,dm1=0,lm1=0,li,di,smax=-1;
in>>n>>m;
for(int i=1;i<=m;i++)
{
in>>di>>li;
if(lm==0)
lm=li,dm=di;
else if(lm1==0)
lm1=li,dm1=di;
else if(lm+dm<li+di)
lm=li,dm=di;
else if(lm1+dm1<li+di)
lm1=li,dm1=di;
}
if(dm>dm1)
out<<lm+lm1+dm-dm1;
else out<<lm+lm1+dm1-dm;
return 0;
}