Pagini recente » Cod sursa (job #156840) | Cod sursa (job #2464976) | Cod sursa (job #2035485) | Rating Alexandru Pana (alexpana) | Cod sursa (job #3172271)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ( "orase.in" );
ofstream fout ( "orase.out" );
const int N = 1e6;
struct oras {
long long d, l;
} v[N + 10];
bool cmp ( oras a, oras b ) {
return a.d < b.d;
}
int main () {
int n, m;
long long val = 0, ans = 0;
fin >> n >> m;
for ( int i = 0; i < m; i++ )
fin >> v[i].d >> v[i].l;
sort ( v, v + m, cmp );
val = ans = v[0].l + v[0].d;
for ( int i = 1; i < m; i++ ) {
ans = max ( ans, val + v[i].l + v[i].d );
val = max ( val, v[i].l - v[i].d );
}
fout << ans;
return 0;
}