Cod sursa(job #2334758)

Utilizator Dragne.Andrei11Dragne Andrei Dragne.Andrei11 Data 3 februarie 2019 00:11:50
Problema Orase Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
#define INF 3000005

using namespace std;

const int nmax=50005;

struct numere
{
    int l;
    int d;
};

numere ini[nmax];
numere v[nmax];

bool cmp(numere a, numere b)
{
    if(a.d==b.d)
        return a.l>b.l;
    return a.d<b.d;
}

int main()
{
    freopen("orase.in", "r", stdin);
    freopen("orase.out", "w", stdout);
    int m, n, rasp=-INF;

    scanf("%d%d", &m, &n);
    for(int i=1;i<=n;i++)
        scanf("%d%d", &ini[i].d, &ini[i].l);
    sort(ini+1, ini+n+1, cmp);
    int k=1;
    for(int i=1;i<=n;i++)
    {
        v[k].l=ini[i].l;
        v[k++].d=ini[i].d;
        while(ini[i].d==ini[i+1].d&&i<=n)
            i++;
    }
    for(int i=1;i<k;i++)
        for(int j=i+1;j<k;j++)
            rasp=max(rasp, v[j].l+v[i].l+v[j].d-v[i].d);
    printf("%d\n", rasp);

    return 0;
}