Pagini recente » Cod sursa (job #1942101) | Cod sursa (job #978125) | Cod sursa (job #780316) | Cod sursa (job #353801) | Cod sursa (job #2554907)
#include <iostream>
#include <fstream>
#include <algorithm>
#define f first
#define s second
#define dm 50005
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");
struct oras{
int l;
int d;
};
bool compare1(oras x, oras y){
if(x.l==y.l)
return x.d>y.d;
return x.l>y.l;
}
bool compare2(oras x, oras y){
if(x.d==y.d)
return x.l<y.l;
return x.d<y.d;
}
oras v[dm];
int n,m;
long long rez1,rez2;
int main(){
fin>>m>>n;
for(int i=1;i<=n;i++)
fin>>v[i].d>>v[i].l;
sort(v+1,v+n+1,compare1);
rez1 = v[1].l+v[2].l+abs(v[1].d-v[2].d);
sort(v+1,v+n+1,compare2);
rez2 = v[1].l+v[n].l+abs(v[1].d-v[n].d);
if(rez1>rez2)
fout<<rez1;
else fout<<rez2;
}