Pagini recente » Cod sursa (job #1781544) | Cod sursa (job #1881344) | Istoria paginii runda/avram_simulare_3/clasament | Cod sursa (job #713366) | Cod sursa (job #2045792)
#include <bits/stdc++.h>
using namespace std;
FILE * fi = fopen("energii.in", "r");
FILE * fo = fopen("energii.out", "w");
int g,w,e,c;
int lcurent=1;
int DP[2][5005];
int main()
{
for(int j=1; j<=5001; j++)
DP[0][j]=DP[1][j]=2000000000;
fscanf(fi,"%d%d",&g,&w);
for(int i=1; i<=g; i++)
{
fscanf(fi,"%d%d",&e,&c);
for(int j=1; j<=e; j++)
DP[lcurent][j]=min(c,DP[1-lcurent][j]);
for(int j=e+1; j<=w; j++)
DP[lcurent][j]=min(DP[1-lcurent][j],DP[1-lcurent][j-e]+c);
lcurent=1-lcurent;
}
if(DP[1-lcurent][w]==2000000000)
fprintf(fo,"%d",-1);
else
fprintf(fo,"%d",DP[1-lcurent][w]);
fclose(fi);
fclose(fo);
return 0;
}