#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i= 0; i<(n); i++)
#define reps(i,s, n) for(int i= (s); i<(n); i++)
#define each(a, x) for (auto &a : x)
#define vv(T) vector<T>
#define endl '\n'
#define sz(x) (int)x.size()
#define ll long long
#define all(c) begin(c), end(c)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define wr cout<<
#define wre wr endl;
#define wrut(a) {wre each(i,(a))wr i<<" "; wre}
#define wrot(a,b,c) {wre wr a<<" "<<b<<" "<<c; wre}
#define int ll
constexpr int K =2e3;
vector<pair<int,int>>items[K+1];
int dpn[K], dp[K];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, s; cin>>s>>n;
int v,w,k;
rep(i,n){
cin>>v>>w>>k;
items[w].pb({v,k});
}
rep(i,w)sort(all(items[i+1]), greater<pair<int,int>>());
reps(i,1,s+1){
if (items[i].empty())continue;
int ile=0, sum=items[i][0].se,done=0;
while(done*i<=s+1&&ile<sz(items[i])){
reps(x,1,s+1){
int &d = dpn[x];
d= dp[x];
if (x<i)continue;
d=max(d,items[i][ile].fi+dp[x-i]);
}
sum--;
done++;
swap(dp,dpn);
if (sum==0){
ile++;
if (ile==sz(items[i]))break;
sum=items[i][ile].se;
}
}
}
wr *max_element(all(dp));
}
# | 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... |