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 int long long
using namespace std;
int n , s , dp[2005];
vector<pair<int , int>> a[2005];
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> s >> n;
for(int i = 1 ; i <= n ; i ++){
int v , w , k;
cin >> v >> w >> k;
a[w].push_back({v , k});
// s[w] += k;
}
for(int i = 1 ; i <= s ; i ++){
if(!a[i].empty()) sort(a[i].begin() , a[i].end() , greater<pair<int , int>>());
}
for(int i = 1 ; i <= s ; i ++){
if(a[i].empty()) continue;
int ind = 1 , sum = 1 , j = 1;
while(sum <= s / i && ind <= (int)a[i].size()){
if(a[i][ind - 1].second < j){
++ind;
j = 1;
}
if(ind > (int)a[i].size()) continue;
for(int c = s ; c >= i ; c --){
dp[c] = max(dp[c] , dp[c - i] + a[i][ind - 1].first);
}
++sum , ++j;
}
}
cout << dp[s];
}
# | 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... |