Submission #594416

#TimeUsernameProblemLanguageResultExecution timeMemory
594416victor_gaoKnapsack (NOI18_knapsack)C++17
100 / 100
106 ms2892 KiB
//#pragma GCC optimize("Ofast,unroll-loops,O3") //#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native") #include<bits/stdc++.h> //#include<bits/extc++.h> //#pragma pack(1) #define fast ios::sync_with_stdio(0); cin.tie(0); #define int long long #define pii pair<int,int> #define x first #define y second using namespace std; //using namespace __gnu_pbds; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset; //typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set; int n,s; int dp[2015]; multiset<int>mx[2015]; signed main(){ fast cin>>s>>n; for (int i=1;i<=n;i++){ int v,w,k; cin>>v>>w>>k; int np=1; while (k>0){ int use=min(k,np); int sz=w*use; int val=v*use; k-=np; np*=2; if (sz>s) continue; mx[sz].insert(val); if (sz*(int)(mx[sz].size())>s) mx[sz].erase(mx[sz].begin()); } } for (int i=1;i<=s;i++){ for (auto k:mx[i]){ for (int j=s;j>=i;j--){ dp[j]=max(dp[j],dp[j-i]+k); } } } cout<<dp[s]<<'\n'; }
#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...