이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
ll int mod = 1e9 + 7;
void solve() {
ll int s, n; cin >> s >> n;
// vector<array<ll int, 3>> arr;
map<int, vector<pair<int, int>>> by_weight;
for (int i = 0; i < n; i++) {
// int a, b, c; cin >> a >> b >> c;
// if (b > s) continue;
// arr.push_back({a, b, c});
int a, b, c; cin >> a >> b >> c;
by_weight[b].push_back(make_pair(a, c));
}
vector<ll int> dp(s + 1, 0);
for (auto &[_weight, items] : by_weight) {
int weight = _weight;
sort(all(items));
reverse(all(items));
for (int i = 0; i < min((ll int)(items.size()), s); i++) {
pair<int, int> cur = items[i];
for (int j = s; j >= 1; j--) {
int cnt = 1;
while (j - cnt * weight >= 0 && cnt <= cur.second) {
dp[j] = max(dp[j], dp[j - cnt * weight] + cnt * cur.first);
cnt++;
}
}
}
}
cout << dp[s] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// int t; cin >> t;
// while (t--)
solve();
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... |