This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct Item {
long long v , w , k;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int S , N;
cin >> S >> N;
vector<Item> a(N);
for (int i = 0 ; i < N ; i++) {
cin >> a[i].v >> a[i].w >> a[i].k;
a[i].k = min(a[i].k , S * 1LL);
}
vector<long long> dp(S + 1);
vector<bool> Reachable(S + 1);
Reachable[0] = true;
for (int i = 0 ; i < N ; i++) {
vector<long long> Temp = dp;
vector<bool> Temp_r = Reachable;
for (long long how = a[i].k ; how >= 1 ; how--) {
vector<long long> new_dp = Temp;
vector<bool> new_Reach = Temp_r;
for (long long j = S - a[i].w * how ; j >= 0 ; j--) {
if (j + a[i].w * how <= S && new_Reach[j]) {
Reachable[j + a[i].w * how] = true;
dp[j + a[i].w * how] = max(dp[j + a[i].w * how] , dp[j] + 1LL * a[i].v * how);
}
}
}
}
cout << *max_element(dp.begin(),dp.end()) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |