#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define st first
#define nd second
#define int long long
using namespace std;
const int lim = 2e5+1;
const ll mod = 1e9+7;
const int base = 31;
const int maxn = 1e5+5;
const int inf = 1e18;
main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,s; cin >> s >> n;
vector <vector <pair<int,int> > > a(s+1);
for(int i = 0; i <n;++i){
int v,w,k;
cin >> v >> w>>k;
a[w].pb({v,k});
}
vector <int> dp(s+1,0);
for(int x = 1 ; x <= s;++x){
if(a[x].empty()) continue;
vector <int> item;
sort(a[x].begin(),a[x].end(),greater<>());
int mx = s/x;
int cnt = 0;
for(auto [v,k] : a[x]){
while(k > 0 and item.size() < mx){
item.pb(v);
k--;
}
}
for(int v : item){
for(int j = s; j >= x;--j){
dp[j] = max(dp[j],dp[j-x] + v);
}
}
}
cout << dp[s] << endl;
return 0;
}
Compilation message (stderr)
knapsack.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
21 | main() {
| ^~~~
# | 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... |