이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int s, n;
cin >> s >> n;
vector<vector<pair<ll, int>>> a(s+1);
for(int i = 0; i < n; i++){
ll v, w, k;
cin >> v >> w >> k;
a[w].push_back({v, k});
}
for(int w = 1; w <= s; w++){
sort(a[w].begin(), a[w].end(), greater<pair<ll, int>>());
}
vector<vector<ll>> dp(2, vector<ll> (s+1));
for(int w = 1; w <= s; w++){
ll tot_weight = 0, tot_val = 0;
for(auto pr : a[w]){
while(pr.S > 0 && tot_weight <= s){
tot_weight += w;
tot_val += pr.F;
pr.S--;
for(int i = s; i >= tot_weight; i--){
dp[1][i] = max(dp[1][i], tot_val + dp[0][i - tot_weight]);
}
}
}
dp[0] = dp[1];
}
cout << dp[0][s] << "\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... |