제출 #938850

#제출 시각아이디문제언어결과실행 시간메모리
938850andrewpKnapsack (NOI18_knapsack)C++14
12 / 100
2 ms2796 KiB
//Dedicated to my love, ivaziva #define yes cout << "YES\n" #define no cout << "NO\n" #define pr cerr<<"DBGDBGDBGDBGDBGDBGDBGDBGDBGDBGDBG\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include "bits/stdc++.h" #define ll long long #define ld long double #define llinf 100000000000000000LL #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define all(a) a.begin(),a.end() #define sz(s) (ll)(s.size()) #define ios ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); #define mod 1000000007 using namespace std; /*#include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; ll add(ll x,ll y){ if(x+y>=mod) return x+y-mod; return x+y; } ll sub(ll x,ll y){ if(x-y<0) return x-y+mod; return x-y; } ll mul(ll x,ll y){ ll res=(x*y)%mod; if(res<0) res+=mod; return res; } ll pw(ll x,ll y){ ll ret=1,bs=x; for(;y;y>>=1){ if(y&1) ret=mul(ret,bs); bs=mul(bs,bs); } return ret%mod; }*/ #define maxn 2005 ll n,s; ll v[maxn],w[maxn]; vector<pll> c[maxn]; void tc(){ cin >> s >> n; for(ll i = 1;i<=n;i++){ ll vu,wu,k; cin >> vu >> wu >> k; c[wu].pb({vu,k}); } ll id=1; for(ll i = 1;i<=s;i++){ sort(c[i].rbegin(),c[i].rend()); ll mx=s/i,cnt=0; for(ll j = 0;j<sz(c[i]);j++){ for(ll k = 0;k<min(c[i][j].sc,mx-cnt);k++){ v[id]=c[i][j].fi; w[id]=i; id++; } } } --id; n=id; ll dp[n+1][s+1][2]; for(ll i = 1;i<=n;i++){ for(ll j = 1;j<=s;j++) dp[i][j][0]=0ll,dp[i][j][1]=0ll; } dp[1][0][0]=0; dp[1][w[1]][1]=v[1]; for(ll i = 2;i<=n;i++){ for(ll j = 0;j<=s;j++){ dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1]); if(j+w[i]<=s){ dp[i][j+w[i]][1]=max(dp[i][j+w[i]][1],dp[i-1][j][0]+v[i]); dp[i][j+w[i]][1]=max(dp[i][j+w[i]][1],dp[i-1][j][1]+v[i]); } } } ll ans=0; for(ll i = 0;i<=s;i++){ ans=max(ans,max(dp[n][i][0],dp[n][i][1])); if(ans==70) dbg(i); } cout<<ans<<endl; } int main(){ ios int t; t = 1; // cin >> t; while(t--){ tc(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...