Cod sursa(job #2254509)

Utilizator BGondaGonda George Luis Bogdan BGonda Data 5 octombrie 2018 14:56:29
Problema Energii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int Inf = 0x3f3f3f3f;
int n, G , cant, cost, v[10001];
 
int main()
{
    fin >> n >> G;
    for(int i=1;i<=G;i++)
        v[i]=Inf;
    for(int i=1;i<=n;i++)
    {
        fin >> cant >> cost;
        for(int j = G;j >= 0; --j)
            {
            if(j>cant)
                v[j]=min(v[j-cant]+cost,v[j]);
            else
                v[j]=min(v[j],cost);
            }
    }
 
  if(v[G] == Inf)
     fout << -1;
  else
     fout << v[G];
 
  return 0;
}