Cod sursa(job #2717940)
Utilizator | Voicu Mihai Valeriu cadmium_ | Data | 8 martie 2021 11:05:04 |
---|---|---|---|
Problema | Orase | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.51 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("orase.in");
ofstream cout("orase.out");
struct city {
int d, h;
bool operator< (const city& x) const {
return d<x.d;
}
}v[50000];
int main() {
int n,maxx,bestuntil;
cin >> n >> n;
for(int i=0; i<n; i++)
cin >> v[i].d >> v[i].h;
sort(v,v+n);
maxx=0;
bestuntil=v[0].h-v[0].d;
for(int i=1; i<n; i++) {
maxx=max(maxx,bestuntil+v[i].h+v[i].d);
bestuntil=max(bestuntil,v[i].h-v[i].d);
}
cout << maxx << '\n';
}