Cod sursa(job #2378121)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 11 martie 2019 18:08:49
Problema Orase Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <iostream>
#include <algorithm>

using namespace std;

ifstream fin  ("orase.in");
ofstream fout ("orase.out");

int m, n, k, i, j;
int L[50005], D[50005];

long long sol;

pair <int, int> cit[50005];

int main(){
    fin >> m >> n;
    for (i=1; i<=n; i++){
        fin >> cit[i].first >> cit[i].second;
    }
    sort (cit + 1, cit + n + 1);
    for (i=1; i<=n; i++){
        L[i] = cit[i].first;
        D[i] = L[i] + cit[i].second;
    }
    sol = -1;
    for (i=1; i<n; i++){
        for (j=i+1; j<=n; j++){
            //distanta de la i la j
            //fout << "distanta de la " << i << " la " << j << " este: " << D[j] + D[i] - 2*L[i] << "\n";
            sol = max (sol, (long long) (D[j] + D[i] - 2*L[i]));
        }
    }
    fout << sol;
    return 0;
}