Cod sursa(job #1536660)

Utilizator FlorinHajaFlorin Gabriel Haja FlorinHaja Data 26 noiembrie 2015 14:46:07
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include <algorithm>
#define formula(x) rez-(a[j].t-a[j-1].t-(x))*c

using namespace std;

ifstream f("carnati.in");
ofstream g("carnati.out");

int n, c, i, j, max1;

struct J{
    int t, p;
}a[2001];

int rez, r1, max0;

bool cmp(J a, J b)
{
    return (a.t < b.t);
}

int main()
{
    f >> n >> c;
    for (i = 1; i <= n; i++)
        f >> a[i].t >> a[i].p;
    sort(a+1, a+n+1, cmp);
    a[0].t = -1;
    for (i = 1; i <= n; i++)
    {
        max0 = a[i].p, rez = 0;
        for (j = 1; j <= n; j++)
        {
            r1 = 0;
            if (a[j].p >= max0)
                r1 = max0;
            if (rez  -  (a[j].t-a[j-1].t-1)*c > 0)
                rez += r1-(a[j].t-a[j-1].t)*c;
            else
                rez = r1-c;
            if (max1 < rez)
                max1 = rez;
        }
    }
    g << max1;
    return 0;
}