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>
#define int long long
#define endl '\n'
#define fi first
#define se second
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int s, n;
cin >> s >> n;
if (n == 1){
int v, w, k;
cin >> v >> w >> k;
int ans = 0;
while(s >= w && k > 0){
s -= w;
ans += v;
k--;
}
cout << ans;
return 0;
}
vector<pair<int, int>> stuff;
for (int i = 0; i < n; i++){
int v, w, k;
cin >> v >> w >> k;
for (int j = 0; j < k; j++){
stuff.push_back({v, w});
}
}
int num = stuff.size();
vector<int> dp(s+1, 0);
for (int i = 0; i < num; i++){
for (int j = s; j >= stuff[i].se; j--){
dp[j] = max(dp[j], dp[j-stuff[i].se] + stuff[i].fi);
}
}
cout << dp[s];
}
# | 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... |