Mai intai trebuie sa te autentifici.
Cod sursa(job #1265794)
| Utilizator | Data | 17 noiembrie 2014 19:26:58 | |
|---|---|---|---|
| Problema | Energii | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.76 kb |
#include<fstream>
using namespace std;
int e[10001], c[10001];
int cost[15002];
//cost[j] = costul minim necesar pt. produce energia j
int main()
{
ifstream in("energii.in");
ofstream out("energii.out");
int g,w,i,j;
int emax=0;
in>>g>>w;
for(i=1;i<=g;i++)
{
in>>e[i]>>c[i];
if(e[i]>emax) emax = e[i];
}
for(j=1; j<=w+emax; j++)
cost[j] = 10002;
for(i=1;i<=g;i++)
{
for (j = w - 1; j >= 0; j--)
if (cost[j]!=10002 && cost[j] + c[i] < cost[j + e[i]])
cost[j+e[i]] = cost[j] + c[i];
}
int r = 10002;
for(i=w;i<=w+emax;i++)
if(cost[i]<r) r=cost[i];
if(r==10001) out<<"-1";
else out<<r;
return 0;
}
