Pagini recente » Cod sursa (job #1822144) | Cod sursa (job #689899) | Cod sursa (job #749280) | Cod sursa (job #955) | Cod sursa (job #1477747)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a, pair <int, int> b){
return a.first < b.first;
}
int main(){
ifstream f("orase.in");
ofstream g("orase.out");
int n, m, i, j, x, y, s;
vector <pair <int, int> > a;
f >> m >> n;
for (i = 0; i < n; ++i){
f >> x >> y;
a.push_back(make_pair(x, y));
}
sort(a.begin(), a.end(), cmp);
i = s =0;
for (j = 1; j < n; ++j){
x = a[j].first + a[j].second + a[i].second-a[i].first;
if (a[j].second > x - a[j].second)i = j;
if (s < x)s = x;
}
g << s;
f.close();
g.close();
return 0;
}