Cod sursa(job #873590)

Utilizator bratiefanutBratie Fanut bratiefanut Data 7 februarie 2013 13:58:32
Problema Energii Scor 5
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");
int n,i,j,R,v[100000],ii,G,E;
int main ()
{
    f>>n>>R;
    for(i=1; i<=n; i++)
    {
        f>>G>>E;

        for(j=1; j<=R; j++)
        {
            if(v[j-G]!=0&&j-G!=0)
            if(v[j]>v[j-G]+E)
            v[j]=v[j-G]+E;
            if(v[j-G]==0&&j-G==0)
            v[j]=E;
        }
    }
if(v[R]>=R)
g<<v[R];
    else
    g<<-1;
return 0;
}