Pagini recente » Cod sursa (job #3231661) | Cod sursa (job #2475428) | Cod sursa (job #1136369) | Cod sursa (job #2366797) | Cod sursa (job #686813)
Cod sursa(job #686813)
#include<fstream>
#define lim 5002
#define lim2 10010
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,G,i,g,Profit[2][lim2],x;
struct dt {
int w,p;
}
v[lim];
void read(){
fin>>n>>G;
for(int i=1;i<=n;i++)
fin>>v[i].w>>v[i].p;
}
int max(int a,int b){
if(a>b)
return a;
return b;
}
void solve(){
x=0;
for(int i=1;i<=n;x=1-x,i++){
for(int g=0;g<=G;g++){
if(v[i].w<=g){
Profit[1-x][g]=max(Profit[x][g],Profit[x][g-v[i].w]+v[i].p);
}
else
Profit[1-x][g]=Profit[x][g];
}
}
}
void print(){
fout<<Profit[x][G];
}
int main (){
read();
solve();
print();
return 0;
}