Submission #533642

#TimeUsernameProblemLanguageResultExecution timeMemory
533642900iqNoobieKnapsack (NOI18_knapsack)C++17
49 / 100
145 ms262148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int const mod=998244353; ll dp[20002][2002]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; while (t--){ int n,s,w,k; ll va; cin>>s>>n; if (n==1){ cin>>va>>w>>k; cout<<va*(min(k,s/w))<<"\n"; continue; } vector <pair<ll,int>> v; v.push_back({(ll)0,0}); for (int i=0;i<n;i++){ cin>>va>>w>>k; k=min(k,2000); while (k--) v.push_back({va,w}); } dp[0][0]=0; for (int i=1;i<v.size();i++){ for (int j=0;j<=s;j++){ dp[i][j]=dp[i-1][j]; if ((v[i].second)<=j) dp[i][j]=max(dp[i][j],dp[i-1][j-(v[i].second)]+(v[i].first)); } } cout<<dp[v.size()-1][s]<<"\n"; } return 0; }

Compilation message (stderr)

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