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>
#define pb push_back
#define int long long
using namespace std;
vector<pair<int, int>> compression(int n, vector<int>& v, vector<int>& w, vector<int>& k) {
map<pair<int, int>, int> comp;
for (int i = 0; i < n; ++i) {
comp[{v[i], w[i]}] += k[i];
}
for (auto& x : comp) {
if (x.second >= 3) {
comp[{2 * x.first.first, 2*x.first.second}] += (x.second - 1) / 2;
if (x.second % 2) comp[x.first] = 1;
else comp[x.first] = 2;
}
}
vector<pair<int, int>> products;
for (auto& x : comp) {
products.pb(x.first);
if (x.second == 2) products.pb(x.first);
}
return products;
}
signed main() {
int s, n;
cin >> s >> n;
vector<int> v(n), w(n), k(n);
for (int i = 0; i < n; ++i) {
cin >> v[i] >> w[i] >> k[i];
}
vector<pair<int, int>> products = compression(n, v, w, k);
int N = (int)products.size();
vector<vector<int>> dp(N+1, vector<int>(s+1, 0));
for (int i = 0; i < N; ++i) {
for (int j = 1; j <= s; ++j) {
dp[i+1][j] = dp[i][j];
if (j >= products[i].second)
dp[i+1][j] = max(dp[i+1][j], dp[i][j-products[i].second]+products[i].first);
}
}
cout << dp[N][s] << '\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... |