Mai intai trebuie sa te autentifici.
Cod sursa(job #1585866)
Utilizator | Data | 31 ianuarie 2016 15:53:06 | |
---|---|---|---|
Problema | Orase | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.78 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
const int dmax = 50000;
struct ELEMENT {int d, L;};
ELEMENT m[dmax + 1];
int Dist_max;
int M, N;
bool exc(ELEMENT e1, ELEMENT e2)
{
if(e1.d == e2.d) return e1.L < e2.L;
else
return e1.d < e2.d;
}
int main()
{
int i, j, dist;
in >> M >> N;
for(i = 1; i <= N; i++) in >> m[i].d >> m[i].L;
sort(m + 1, m + N + 1, exc);
for(i = 1; i <= N; i++)
for(j = i + 1; j <= N; j++)
{
if(m[j].d == m[i].d) dist = m[j].L - m[i].L;
else
dist = m[i].L + ( m[j].d - m[i].d ) + m[j].L;
Dist_max = max(Dist_max, dist);
}
out << Dist_max;
return 0;
}