Cod sursa(job #1265909)

Utilizator Corina1997Todoran Ana-Corina Corina1997 Data 17 noiembrie 2014 22:18:42
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>
#include <vector>
#define INF 0x3f3f3f3f
using namespace std;

ifstream is("energii.in");
ofstream os("energii.out");

int n, S, x, y;
vector<int> a;

int main()
{
    is >> n >> S;
    a.resize(S+1, INF);
    a[0] = 0;
    for ( int i = 1 ; i <= n; i++ )
    {
        is >> x >> y;
        for ( int j = x; j <= S; j += x )
            a[j] = min( a[j-x] + y, a[j] );
    }
    os << a[S];
    return 0;
}