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<iostream>
#include<string>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#include<vector>
using namespace std;
int mod = 1000000007;
int s, n;
const int N = 100001;
vector<long long> c(N, 0);
vector<long long> w(N, 0);
vector<long long> q(N, 0);
long long solve() {
vector<long long> dp(s+1, -1);
long long ans = 0;
dp[0] = 0;
for (int i=1; i<=n; i++) {
for (int j=s; j>=0; j--) {
//buy from 0 to q[i] of good i
for (int k=0; k<=q[i]; k++) {
if (j-k*w[i] < 0) break;
if (dp[j-k*w[i]] == -1) continue;
dp[j] = max(dp[j], dp[j-k*w[i]] + c[i] * k);
}
ans = max(ans, dp[j]);
}
}
return ans;
}
int main() {
cin >> s >> n;
for (int i=1; i<=n; i++) cin >> c[i] >> w[i] >> q[i];
cout << solve() << "\n";
}
# | 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... |