Cod sursa(job #2289800)

Utilizator YouDontNeedMyNameJurcut Paul YouDontNeedMyName Data 25 noiembrie 2018 12:05:16
Problema Energii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
#define inf 10000005
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
int v[15005],n,c,x,y,ma=inf;
int main()
{
    in >> n >> c;
    for(int i=1; i<=c; i++)
    {
        v[i]=inf;
    }
    for(int i=1; i<=n; i++)
    {
        in >> x >> y;
        for(int j=c; j>=0; j--)
        {
            if(v[j]!=inf)
            {
                if(j+x>=c)
                {
                    v[c]=min(v[c],v[j]+y);
                }
                else
                {
                    v[j+x]=min(v[j+x],v[j]+y);
                }
            }
        }
    }
    if(v[c]==inf)
    {
        out << -1;
        return 0;
    }
    out << v[c];
    return 0;
}