Cod sursa(job #1923317)

Utilizator stelian2000Stelian Chichirim stelian2000 Data 10 martie 2017 22:26:08
Problema Energii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <cstdio>
#include <algorithm>

using namespace std;

const int INF=1e9;

int d[10010];

int main()
{
    freopen("energii.in","r",stdin);
    freopen("energii.out","w",stdout);
    int g,w,e,c;
    scanf("%d%d",&g,&w);
    for(int i=1;i<=2*w;i++) d[i]=INF;
    for(int i=1;i<=g;i++)
    {
        scanf("%d%d",&e,&c);
        for(int i=2*w;i>=e;i--)
            d[i]=min(d[i],d[i-e]+c);
    }
    int sol=INF;
    for(int i=w;i<=2*w;i++) sol=min(sol,d[i]);
    if(sol>=INF) printf("-1");
    else printf("%d",sol);
    return 0;
}