Submission #1044387

#TimeUsernameProblemLanguageResultExecution timeMemory
1044387sanatp977Knapsack (NOI18_knapsack)C++17
100 / 100
36 ms2976 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(0); cin.tie(0); int s,n; cin>>s>>n; vector<pair<int,int>>arr[2001]; for(int i=0;i<n;i++){ int v,w; ll k; cin>>v>>w>>k; arr[w].push_back({v,k}); } ll dp[2001]; memset(dp,0,sizeof dp); ll ans = 0; for(int i=1;i<=s;i++){ sort(arr[i].begin(),arr[i].end(),greater<pair<int,ll>>()); int index = 0; for(int j=0;j<s/i;j++){ if(index>=arr[i].size())break; for(int x=s;x>=i;x--){ dp[x]=max(dp[x],dp[x-i]+arr[i][index].first); ans=max(ans,dp[x]); } arr[i][index].second-=1; if(arr[i][index].second==0)index++; } } cout<<ans<<"\n"; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:19:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |             if(index>=arr[i].size())break;
      |                ~~~~~^~~~~~~~~~~~~~~
#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...