Submission #860754

#TimeUsernameProblemLanguageResultExecution timeMemory
860754noyancanturkKnapsack (NOI18_knapsack)C++17
100 / 100
39 ms3040 KiB
#ifndef Local #pragma GCC optimize("O3,unroll-loops") #endif #include <bits/stdc++.h> #define int long long #define pb push_back #define lim 100000 using namespace std; const int mod=1000000007ll; void solve(){ int s,n; cin>>s>>n; priority_queue<pair<int,int>>weight[s+1]; for(int i=0;i<n;i++){ int v,w,k; cin>>v>>w>>k; weight[w].push({v,k}); } int dp[s+1]; memset(dp,0,sizeof(dp)); for(int i=1;i<=s;i++){ int cani=s/i,j=0; while(cani&&weight[i].size()){ auto p=weight[i].top(); weight[i].pop(); int to=min(p.second,cani); for(int rep=0;rep<to;rep++){ for(int j=s-i;0<=j;j--){ dp[j+i]=max(dp[j+i],dp[j]+p.first); } } cani-=to; } } cout<<*max_element(dp,dp+s+1); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifdef Local freopen(".in","r",stdin); freopen(".out","w",stdout); #endif int t=1; //cin>>t; while (t--) { solve(); } }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:23:22: warning: unused variable 'j' [-Wunused-variable]
   23 |         int cani=s/i,j=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...