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>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pp;
#define rep(i,l,r) for(int i = (l); i < r; i++)
#define per(i,r,l) for(int i = (r); i >= l; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define ss second
const ll mod = 1e9 + 7, maxn = 2e2 + 5, inf = ll(1e18) + 5;
int main(){
cin.tie(0) -> sync_with_stdio(0);
int s, n; cin >> s >> n;
vector<vector<pp>> a(s + 1);
rep(i,0,n){
int w, v, k; cin >> v >> w >> k;
k = min(k, s);
a[w].pb({v, k});
}
vector<vector<ll>> dp(s + 1, vector<ll>(s + 1));
rep(i,1,s + 1){
sort(all(a[i])); reverse(all(a[i]));
vector<ll> prf(s/i + 1);
int pt = 1;
for(auto [v, k]: a[i]){
while(k-- && pt != sz(prf)) prf[pt] = prf[pt-1] + v, pt++;
}
rep(j,1,s + 1){
rep(k,0,sz(prf)){
if(j < k*i) break;
dp[i][j] = max(dp[i][j], dp[i-1][j-k*i] + prf[k]);
}
}
}
cout << dp[s][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... |