Submission #533649

#TimeUsernameProblemLanguageResultExecution timeMemory
533649900iqNoobieKnapsack (NOI18_knapsack)C++17
73 / 100
1069 ms132968 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int const mod=998244353; ll dp[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; int r=(s/w); k=min(k,r); r=1; while (k-r>=0){ v.push_back({va*r,w*r}); k-=r; r++; } if (k) v.push_back({va*k,w*k}); } for (int i=1;i<v.size();i++){ for (int j=s;j>=v[i].second;j--){ dp[j]=max(dp[j],v[i].first+dp[j-v[i].second]); } } cout<<dp[s]<<"\n"; } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:35: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]
   35 |         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...