Cod sursa(job #1450068)

Utilizator delia_99Delia Draghici delia_99 Data 11 iunie 2015 12:34:27
Problema Peste Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

struct aww
{
    int fish,time;
};

int n,k,T,i,Max,s,aux[1010],j;
long long D[50010];
aww v[50010];

priority_queue <int, vector<int>, greater<int> >H;

inline bool cmp(aww A,aww B)
{
    if(A.time<B.time)
        return true;
    if(A.time==B.time && A.fish<B.fish)
        return true;
    return false;
}

int main()
{
    freopen("peste.in","r",stdin);
    freopen("peste.out","w",stdout);
    scanf("%d %d %d\n",&n,&k,&T);
    for(i=1; i<=n; ++i)
    {
        scanf("%d %d\n",&v[i].fish,&v[i].time);
        if(v[i].time>Max)
            Max=v[i].time;
    }
    sort(v+1,v+n+1,cmp);
    for(i=1; i<=n; ++i)
    {
        H.push(v[i].fish);
        s+=v[i].fish;
        if(i>k)
        {
            s-=H.top();
            H.pop();
        }
        aux[v[i].time]=s;
    }
    for(i=1; i<=n; ++i)
        aux[i]=max(aux[i-1],aux[i]);
    for(i=1; i<=T; ++i)
        for(j=1; j<=i && j<=Max; ++j )
            D[i]=max(D[i],D[i-j]+aux[j]);
    printf("%d\n",D[T]);
    return 0;
}