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;
typedef int ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll s, n;
cin >> s >> n;
pair<pair<ll, ll>, ll> shop[n+1];
for (ll i = 1; i <= n; i++) {
cin >> shop[i].first.first >> shop[i].first.second >> shop[i].second;
}
ll dp[2005][2005];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= s; j++) {
dp[i][j] = 0;
}
}
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= s; j++) {
ll cou = 0;
while (cou*shop[i].first.second <= j && cou <= shop[i].second) {
dp[i][j] = max(dp[i][j], dp[i-1][j - cou * shop[i].first.second] + cou * shop[i].first.first);
cou++;
}
}
}
ll ans = 0;
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= s; j++) {
ans = max(ans, dp[i][j]);
}
}
cout << ans;
}
# | 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... |