Cod sursa(job #2472984)

Utilizator CharacterMeCharacter Me CharacterMe Data 13 octombrie 2019 12:13:59
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
#define d first
#define l second
typedef long long ll;
typedef std::pair<ll, ll> pl;
ll n, m, i, j, k, dmax, pos, sol;
pl list[50001];
void read();
void solve();
void write();
int main()
{
    freopen("orase.in", "r", stdin);
    freopen("orase.out", "w", stdout);
    read();
    solve();
    write();
    fclose(stdin);
    fclose(stdout);
    return 0;
}
void read(){
    scanf("%lld%lld", &m, &n);
    for(i=1; i<=n; ++i) scanf("%lld%lld", &list[i].d, &list[i].l);
}
void solve(){
    std::sort(list+1, list+n+1);
    dmax=list[1].l;
    pos=list[1].d;
    for(i=2; i<=n; ++i){
        dmax=dmax+(list[i].d-pos);
        pos=list[i].d;
        sol=std::max(sol, dmax+list[i].l);
        dmax=std::max(dmax, list[i].l);
    }
}
void write(){
    printf("%lld", sol);
}