이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef vector<int> vi;
typedef long long ll;
#define PB push_back
#define MP make_pair
#define FOR(i, x, y) for (int i = x; i < y ; i ++)
int main(){
int s, n;
cin >> s >> n;
vector<pair<ll, ll>> weights[s + 1];
FOR(i, 0, n){
ll v, w, k;
cin >> v >> w >> k;
weights[w].PB(MP(v, k));
}
FOR(i, 0, s){
sort(weights[i].rbegin(), weights[i].rend());
}
ll dp[s + 1] = { 0 };
ll ans = 0;
FOR(j, 1, s + 1){
int indx = 0;
ll prev = 0;
FOR(cnt, 1, s/j + 1){
for(int i = s; i >= 1; i --){
//cout << dp[s] << '\n';
if (j > i || indx >= (int)weights[j].size()){
break;
}
if (cnt - prev > weights[j][indx].second){
prev += weights[j][indx].second;
indx ++;
}
if (indx >= (int)weights[j].size()){
break;
}
dp[i] = max(dp[i], dp[i - j] + weights[j][indx].first);
}
}
}
FOR(i, 1, s + 1){
//cout << i << " : " << dp[i] << '\n';
ans = max(ans, dp[i]);
}
cout << ans << '\n';
}
# | 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... |