/*#pragma GCC optimize("Ofast,no-stack-protector,unroint-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroint-loops")
#pragma ("reroint") */
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define ins insert
#define F first
#define S second
const int mod = 1e9 + 7,N = 5e5 + 100;
signed main(){
//freopen("justcoding.in","r",stdin);
//freopen("justcoding.out","w",stdout);
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int s,n;
cin >> s >> n;
int v,w,k;
vector<pair<int,int>>vv;
int dp[s + 1];
dp[0] = 0;
for(int i = 1;i<=s;i++) dp[i] = -1;
for(int i = 1;i<=n;i++){
cin >> v >> w >> k;
int l = 1;
while(w*l<=s && l<=k){
vv.pb({v,w});
l++;
}
}
for(auto x:vv){
int v = x.F;
int w = x.S;
for(int i = s;i>=w;i--){
if(dp[i-w]!=-1){
dp[i] = max(dp[i-w] + v,dp[i]);
}
}
}
int ans = -1;
for(int i = 0;i<=s;i++){
ans = max(ans,dp[i]);
}
cout << ans << '\n';
}
| # | 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... |