Cod sursa(job #2378134)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 11 martie 2019 18:36:01
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 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 sol1, sol2;

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++){
        D[i] = cit[i].first;
        L[i] = cit[i].second;
        sol1 = max (sol1, (long long) (L[i] - D[i]));
    }
    for (i=1; i<=n; i++){
        sol2 = max ((long long) (L[i] + D[i] + sol1), sol2);
    }
    fout << sol2;
    return 0;
}
//100p
//distanta de la i la j, cu i<j, este: L[j] + D[j] + L[i] - D[i]