This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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 500005
#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;a%=mod;ans%=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<pii,null_type,less_equal<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
void solve(){
int S,n; cin>>S>>n;
vector<vpii> mpp(S+5);
for(int i=1;i<=n;i++){
int v,w,k; cin>>v>>w>>k;
mpp[w].pb({v,k});
}
for(int i=1;i<=S;i++) sort(mpp[i].begin(),mpp[i].end(),greater<pii>());
vector<vi> dp(S+5,vi(S+5)); int ans=0;
for(int i=1;i<=S;i++){
for(int w=1;w<=S;w++){
int adet=0,tot=0;
dp[i][w]=dp[i-1][w];
for(auto u : mpp[i]){
while(u.s--){
adet++; tot+=u.f;
if(adet*i<=w) dp[i][w]=max(dp[i][w],dp[i-1][w-adet*i]+tot);
else break;
}
if(adet*i>w) break;
}
ans=max(ans,dp[i][w]);
}
}
cout<<ans<<endl;
return;
}
int32_t main(/*int32_t argc, char* argv[]*/){
ios_base::sync_with_stdio(0); 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... |