Cod sursa(job #1507645)

Utilizator stud.ubbstud ubb stud.ubb Data 21 octombrie 2015 19:37:39
Problema Problema rucsacului Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <iostream>
using namespace std;
int D[10001];
int N,G;
int W[5001];
int P[5001];

int main(){
cin>> N>>G;
for (int i=0;i<N;i++){
	cin>>W[i]>>P[i];
}
D[0]=0;
int rez=0;
for (int i=0;i<N;i++){
	for (int j=G-W[i];j>=0;j--){
		if (D[j+W[i]]<=D[j]+P[i]){
			D[j+W[i]]=D[j]+P[i];
			if (D[j+W[i]]>rez){
				rez =D[j+W[i]];
			}
		}
	}
}
cout<<rez;
return 0;
}