이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Free at last, Free at last, Thank God Almighty, We are free at last.
*/
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#define ll long long
#define nl cout << '\n'
#define pri(n) cout<<fixed<<setprecision(n)
#define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
void m4_htgeb_tle_kda_ya3ny() {
cin.tie(0);
cin.sync_with_stdio(0);
cout.tie(0);
cout.sync_with_stdio(0);
}
const double eps = -1e-9;
//const long double pi = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
const ll inf = 1e16 + 1;
const int N = 2e5 + 3;
const int W = 2001;
vector<pair<int, int>> cost[W];
void solveCase() {
int n, s;
cin >> s >> n;
for (int i = 0; i < n; ++i) {
int v, w, k;
cin >> v >> w >> k;
cost[w].emplace_back(v, k);
}
for (auto &i: cost)std::sort(i.rbegin(), i.rend());
int dp[s + 1][s + 1];
memset(dp, 0, sizeof dp);
for (int rem = 0; rem <= s; ++rem) {
for (int w = 1; w <= rem; ++w) {
int taken = 0, val = 0;
dp[rem][w] = dp[rem][w - 1];
for (pair<int, int> item: cost[w]) {
for (int ct = 0; ct < item.second && (taken + 1) * w <= rem; ++ct) {
taken++, val += item.first;
dp[rem][w] = max(dp[rem][w], dp[rem - taken * w][min(w - 1, rem - taken * w)] + val);
}
}
}
}
cout << dp[s][s];
}
int main() {
m4_htgeb_tle_kda_ya3ny();
int test = 1;
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
// cin >> test;
for (int i = 1; i <= test; ++i) {
solveCase();
nl;
}
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... |