Pagini recente » Cod sursa (job #1767893) | Cod sursa (job #1213775) | Cod sursa (job #381232) | Cod sursa (job #1067154) | Cod sursa (job #2485010)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int dp[1007];
int main() {
int n, w, x, y, z, pos, maxe = 0, mine = -1;
fin>>n>>w;
for(int i=0;i<n;i++){
fin>>x>>y;
for(int j=maxe;j>=0;j--)
if(dp[j]){
z = dp[j]+y;
pos = x+j;
if(pos>=w && (mine==-1 || z<mine))
mine = z;
else if(pos<w && (dp[pos]==0 || dp[pos]>z))
dp[pos] = z;
}
if(y>maxe) maxe = y;
if(dp[x]==0 || y<dp[x])
dp[x] = y;
}
fout<<mine;
return 0;
}