Cod sursa(job #2554907)

Utilizator DanBarbilianMuresan Dan Adrian DanBarbilian Data 23 februarie 2020 15:04:40
Problema Orase Scor 10
Compilator cpp-64 Status done
Runda corigenta Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define f first
#define s second
#define dm 50005
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");

struct oras{
    int l;
    int d;
};

bool compare1(oras x, oras y){
    if(x.l==y.l)
        return x.d>y.d;
    return x.l>y.l;
}

bool compare2(oras x, oras y){
    if(x.d==y.d)
        return x.l<y.l;
    return x.d<y.d;
}

oras v[dm];
int n,m;
long long rez1,rez2;
int main(){
    fin>>m>>n;
    for(int i=1;i<=n;i++)
        fin>>v[i].d>>v[i].l;
    sort(v+1,v+n+1,compare1);
    rez1 = v[1].l+v[2].l+abs(v[1].d-v[2].d);
    sort(v+1,v+n+1,compare2);
    rez2 = v[1].l+v[n].l+abs(v[1].d-v[n].d);
    if(rez1>rez2)
        fout<<rez1;
    else fout<<rez2;
}