Cod sursa(job #3247254)

Utilizator MMEnisEnis Mutlu MMEnis Data 6 octombrie 2024 16:38:33
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

struct cel
{
    int pret,timp;
}v[2001];

int cmp(cel a,cel b)
{
    if( a.timp != b.timp )
        return a.timp<b.timp;
    return a.pret<b.pret;
}

int main()
{
    int n, t, i, j, poz, maxx=-1;
    f >> n >> t;
    for( i=1; i <=n ; i++ )
        f >> v[i].timp >> v[i].pret;
    sort(v+1, v+n+1, cmp);

    for( i=1; i <= n; i++ )
    {
        int p = v[i].pret;
        int s = 0;
        for( j=1; j <= n; j++ )
        {
            if( v[j].pret >= p )
            {
                poz = v[j].timp - 1;
                break;
            }
        }
        for( j=1; j <= n; j++ )
        {
            if( p <= v[j].pret )
            {
                if( p - t >= s + p - (v[j].timp - poz)*t )
                    s = p - t;
                else s += p - (v[j].timp - poz)*t;
                poz = v[j].timp;
                if( maxx < s)
                    maxx=s;
            }
        }
    }
    g<<maxx;
    return 0;
}