Pagini recente » Cod sursa (job #606391) | Cod sursa (job #1411634) | Cod sursa (job #1593830) | Cod sursa (job #1868398) | Cod sursa (job #1704758)
#include<fstream>
using namespace std;
fstream f("rucsac.in");
ofstream t("rucsac.out");
struct RUC{
int GR, profit;
};
int N, G, S, A[10001];
RUC Q[10001];
int main(){
f>>N>>G;
for(int i=1;i<=N;++i)
f>>Q[i].GR>>Q[i].profit;
for(int i=1;i<=N;++i){
for(int j=G-Q[i].GR;j>=0;j--){
if(A[j+Q[i].GR]<A[j]+Q[i].profit){
A[j+Q[i].GR]=A[j]+Q[i].profit;
if(S<A[j+Q[i].GR])
S=A[j+Q[i].GR];
}
}
}
t<<S;
}