Pagini recente » Cod sursa (job #2443799) | Cod sursa (job #2221162) | Cod sursa (job #1410550) | Cod sursa (job #398255) | Cod sursa (job #1674072)
#include <iostream>
#include <stdio.h>
#define Pretmax 100000000
using namespace std;
int p[5010];
int main(){
int i,j,pow,ener,pret,nrgen;
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
scanf("%d%d",&nrgen,&pow);
for(i=1;i<=pow;i++){
p[i]=Pretmax;
}
for(i=0;i<nrgen;i++){
scanf("%d%d",&ener,&pret);
if(ener>=pow){
if(pret<p[pow]){
p[pow]=pret;
}
continue;
}
for(j=pow-ener;j>=0;j--){
if(p[j+ener]>p[j]+pret ){
p[j+ener]=p[j]+pret;
}
}
}
printf("%d",p[pow]);
return 0;
}