Pagini recente » Cod sursa (job #440412) | Cod sursa (job #1459185) | Cod sursa (job #99060) | Cod sursa (job #1611509) | Cod sursa (job #2785077)
#include<stdio.h>
#define N 5001
#define G 10001
using namespace std;
int weights[N], profits[G];
int max_profits[G];
int max(int a, int b) {
if(a > b) {
return a;
} else {
return b;
}
}
int main() {
FILE *fp1, *fp2;
fp1 = freopen("rucsac.in", "r", stdin);
fp2 = freopen("rucsac.out", "w", stdout);
int n, greutate_maxima, profit_ob_introdus, profit_ob_neintrodus;
scanf("%d %d", &n, &greutate_maxima);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &weights[i], &profits[i]);
}
for (int i = 1; i <= n; ++i)
for(int j = greutate_maxima - weights[i]; j >= 0; --j) {
if (max_profits[j + weights[i]] < max_profits[j] + profits[i]) {
max_profits[j + weights[i]] = max_profits[j] + profits[i];
}
}
printf("%d", max_profits[greutate_maxima]);
fclose(fp1);
fclose(fp2);
return 0;
}