//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define MAX 200005
#define pb push_back
// #define mp make_pair
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>>
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first : key
// myMap.begin()->second : value
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;b>>=1;ans%=mod;a%=mod;}return ans%mod;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sum(int a,int b){return ((a%mod)+(b%mod))%mod;}
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
// typedef
// tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
void solve(){
int S,n; cin>>S>>n;
vector<vpii> types(S+2);
for(int i=1;i<=n;i++){
int v,w,k; cin>>v>>w>>k;
types[w].pb({v,k});
}
for(int i=1;i<=S;i++) sort(types[i].begin(),types[i].end()),reverse(types[i].begin(),types[i].end());
vector<vi> dp(S+2,vi(S+2));
for(int w=1;w<=S;w++){
for(int j=1;j<=S;j++){
int adettot=0, gain=0, k=0;
dp[w][j]=max(dp[w-1][j],dp[w][j-1]);
for(int k=0;k<types[w].size();k++){
int adet=0;
while(adet<types[w][k].s){
adet++; adettot++; gain+=types[w][k].f;
if(adettot*w<=j) dp[w][j]=max(dp[w][j],dp[w-1][j-adettot*w]+gain);
}
}
}
}
int ans=0;
for(int i=1;i<=S;i++) ans=max(ans,dp[S][i]);
cout<<ans<<endl;
}
int32_t main(/*int32_t argc, char* argv[]*/){
std::ios_base::sync_with_stdio(0); std::cin.tie(0);
// freopen("spainting.in", "r", stdin);
// freopen("spainting.out", "w", stdout);
int t=1;
// cin >> t;
while (t--) solve();
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... |