Cod sursa(job #2044942)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 21 octombrie 2017 17:02:55
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>

using namespace std;

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

#define inf 987654321

int n,et,e,cost,i,j,c[1002];
int main()
{
f>>n>>et;

for(i=1;i<=et;i++)
    c[i]=inf;

for(i=1;i<=n;i++)
{
    f>>e>>cost;

    for(j=et;j>=e;j--)
    {
        if(c[j]>c[j-e]+cost)
            c[j]=c[j-e]+cost;
    }

    for(j=e;j>=1;j--)
    {
        if(c[j]>cost)
            c[j]=cost;
    }
}

g<<c[et];

    return 0;
}