Cod sursa(job #2453017)

Utilizator giotoPopescu Ioan gioto Data 2 septembrie 2019 10:47:29
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;

int m, n;

struct elem{
    int x, y;

    bool operator < (const elem &aux)const{
        if(x != aux.x) return x < aux.x;
        return y > aux.y;
    }
};

elem a[50005];

int main()
{
    freopen("orase.in", "r", stdin);
    freopen("orase.out", "w", stdout);

    scanf("%d%d", &m, &n);
    for(int i = 1; i <= n ; ++i)
        scanf("%d %d", &a[i].x, &a[i].y);

    sort(a + 1, a + n + 1);

    int last = a[1].x, s = a[1].y;
    int Sol = 0;
    for(int i = 2; i <= n ; ++i){
        s = s + (a[i].x - last);
        last = a[i].x;

        Sol = max(Sol, s + a[i].y);

        s = max(s, a[i].y);
    }

    printf("%d", Sol);

    return 0;
}