Pagini recente » Cod sursa (job #703900) | Cod sursa (job #626613) | Cod sursa (job #565638) | Cod sursa (job #1732041) | Cod sursa (job #1772249)
#include <iostream>
#include <stdio.h>
using namespace std;
int sums [10001];
int main() {
freopen ("rucsac.in", "r", stdin);
freopen ("rucsac.out", "w", stdout);
int Feed, Limit, Maxi = 0;
int Weight, Value;
cin >> Feed >> Limit;
for (int i = 1; i <= Feed; i++) {
cin >> Weight >> Value;
for (int WGT = Limit - Weight; WGT >= 0; WGT--) {
if (Value + sums [WGT] > sums [WGT + Weight]) {
sums [WGT + Weight] = Value + sums [WGT];
if (sums [WGT + Weight] > Maxi)
Maxi = sums [WGT + Weight];
}
}
}
cout << Maxi;
}