#include<bits/stdc++.h>
#define Daniel_1997 void
using namespace std;
//\\ PRINCIPAL \\//
#define oo 1e18
#define endl "\n"
#define int long long
#define mod 800000007
#define tle while(1){;}
#define ios ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0)
//\\ BITS \\//
#define bits_1 __builtin_popcount
//\\ STL \\//
#define pb push_back
#define fr first
#define sc second
#define lb lower_bound
#define all(x) x.begin(), x.end()
//\\ FAST OPERATIONS \\//
#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)
#define pf(n) printf("%d\n",n)
#define pfl(n) printf("%I64d ",n)
struct c{
int p;
int v;
int k;
};
int32_t main() {
int s,n;
cin >> s >> n;
vector<c>v(n);
for(int i = 0; i < n; i++) {
cin >> v[i].v >> v[i].p >> v[i].k;
if(v[i].k > s)v[i].k = s;
}
for(int i = 0; i < v.size(); i++) {
if(v[i].k > 1) {
int aux = v[i].k;
for(int j = 0; j < v[i].k; j++) {
if(aux >= (1 << j)) {
v.pb({v[i].p * (1 << j),v[i].v * (1 << j),1});
aux -= (1 << j);
}
}
v[i].k = aux;
}
}
vector<int>dp(s + 1,0);
for(int i = 0; i < v.size(); i++) {
if(v[i].k == 0)continue;
for(int j = s; j >= v[i].p; j--) {
dp[j] = max(dp[j],dp[j - v[i].p] + v[i].v);
}
}
int maxx = 0;
for(int i = 0; i < dp.size(); i++) {
maxx = max(maxx,dp[i]);
}
cout << maxx << endl;
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... |