이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define TASK "task"
#define all(x) (x).begin(),(x).end()
#define int long long
const int mxN = 5e5 + 7;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int m;
int dp[mxN];
vector<pair<int,int>>weight[mxN];
signed main() {
//freopen(TASK".inp","r",stdin);
//freopen(TASK".out","w",stdout);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int v,w,k;
cin >> v >> w >> k;
weight[w].emplace_back(make_pair(v,k));
}
for (int i = 1; i <= n; i++) sort(all(weight[i]),greater<pair<int,int>>());
for (int i = 1; i <= n; i++) {
if((int) weight[i].size() == 0) continue;
int cur = 0;
for (int j = 0; j * i < n; j++) {
if(cur >= (int) weight[i].size()) break;
for (int k = n; k >= i; k--) maximize(dp[k],dp[k - i] + weight[i][cur].first);
weight[i][cur].second--;
if(!weight[i][cur].second) ++cur;
}
}
cout << dp[n] << "\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... |