# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866917 | iskhakkutbilim | Knapsack (NOI18_knapsack) | C++17 | 1026 ms | 4048 KiB |
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;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 1e9 + 7;
const int N = 1e5;
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int s, n; cin >> s >> n;
vector<int> v(n+1), w(n+1), k(n+1);
vector<int> dp(s+1, LLONG_MIN);
dp[0] = 0;
for(int i = 1;i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
}
for(int i = 1;i <= n; i++){
for(int round = 1; round * w[i] <= s && round <= k[i]; round++){
for(int d = s; d - w[i] >= 0; d--){
dp[d] = max(dp[d], dp[d-w[i]] + v[i]);
}
}
}
int ans = LLONG_MIN;
for(int i = 0;i <= s; i++){
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |