#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int mod = 1000000007;
#define endl '\n'
#define skip continue
#define uno first
#define duo second
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define GO while(tt--)
#define ins insert
#define pb push_back
#define all(x) x.begin(), x.end()
#define forest signed
#define Kaldun cin.tie(0)->sync_with_stdio(0)
#define int long long
int bp(int a, int n) {
if(n == 0) return 1;
if(n % 2 == 1) return (bp(a, n-1) * 1LL * a) % mod;
long long b = bp(a, n/2);
return (b * b) % mod;
}
signed main() {
//freopen("time.in", "r", stdin);
//freopen("time.out", "w", stdout);
Kaldun;
int s,n;
cin>>s>>n;
vector<pair<int,int>>v;
int va[n+1],wa[n+1],k[n+1];
for(int i=1;i<=n;i++){
cin>>va[i]>>wa[i]>>k[i];
for(int p=1;k[i]>0;p<<=1){
int t=min(p,k[i]);
v.emplace_back(t * va[i] , t*wa[i]);
k[i]-=t;
}
}
int dp[s+1]{};
for (const auto& [v, w] : v) {
for (int j = s; j >= w; --j) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout<<dp[s]<<endl;
}
# | 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... |