Cod sursa(job #2241092)
Utilizator | Data | 14 septembrie 2018 19:16:35 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 65 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int d[5010];
int main(){
int n , g , wt , val , ans = 0;
in >> n >> g ;
while(n--){
in >> wt >> val ;
for(int i = g ; i >= wt ; i --){
d[i] = max(d[i] , val + d[i-wt]);
ans = max(ans,d[i]);
}
}
out << ans ;
return 0 ;
}