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 ll long long
#define val first
#define sl second
#define pii pair<int, int>
const int N = 1e5 + 5;
int n, S;
int dp[2005];
vector<pii> w[N];
bool cmp(pii &a, pii &b) {
return a.val > b.val;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> S >> n;
for(int i = 1; i <= n; ++i) {
int val, W, sl; cin >> val >> W >> sl;
w[W].emplace_back(val, sl);
}
for(int i = 1; i <= S; ++i) {
sort(w[i].begin(), w[i].end(), cmp);
int cnt = 0;
for(pii res : w[i]) {
if(cnt > S / i) break;
for(int j = 1; j <= res.sl; ++j) {
for(int k = S; k >= i; --k) {
dp[k] = max(dp[k], dp[k - i] + res.val);
}
++cnt;
if(cnt > S / i) break;
}
}
}
int ans = 0;
for(int i = 1; i <= S; ++i) ans = max(ans, dp[i]);
cout << ans << '\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... |