Cod sursa(job #2712138)

Utilizator vladboss2323Ciorica Vlad vladboss2323 Data 25 februarie 2021 11:30:44
Problema Orase Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std;

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

struct oras
{
    int d;
    int l;
};

bool cmp(oras A,oras B)
{
    if (A.d != B.d)
        return A.d < B.d;
    else
        return A.l > B.l;
}

int main()
{
    int n,m,i,s,smax = 0;
    vector<oras>a;
    oras x;
    in >> m >> n;
    for (i = 1; i <= n; i++)
    {
        in >> x.d >> x.l;
        a.push_back(x);
    }
    sort(a.begin(),a.end(),cmp);
    while (n > 1)
    {
        s = a[1].l + a[0].l + a[1].d - a[0].d;
        if (s > smax)
            smax = s;
        if (a[1].l >= a[0].l + a[1].d - a[0].d)
        {
            a.erase(a.begin());
            n--;
        }
        else
        {
            a.erase(a.begin() + 1);
            n--;
        }
    }
    out << smax;
    return 0;
}