Submission #934467

#TimeUsernameProblemLanguageResultExecution timeMemory
934467tnknguyen_Knapsack (NOI18_knapsack)C++14
73 / 100
1038 ms18876 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pll pair<long long, long long> const int sz = 1e6 + 5; vector<pll> a; long long f[sz]; long long s, n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("main.inp","r",stdin); //freopen("main.out","w",stdout); cin>>s>>n; for(int i=1;i<=n;++i){ long long v, w, k, p=1; cin>>v>>w>>k; while(p <= k){ k -= p; a.push_back({v*p, w*p}); p *= 2; } if(k > 0){ a.push_back({v*k, w*k}); } } for(int i=0;i<a.size();++i){ for(int j=s;j>=a[i].second;--j){ f[j] = max(f[j], f[j - a[i].second] + a[i].first); } } cout<<f[s]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i<a.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...