Submission #955566

#TimeUsernameProblemLanguageResultExecution timeMemory
955566haileyyKnapsack (NOI18_knapsack)C++14
37 / 100
1 ms600 KiB
//https://oj.uz/problem/view/NOI18_knapsack #include <bits/stdc++.h> #define loop(i, l, r) for(int i = (l); i < (r); ++i) #define pool(i, l, r) for(int i = (l); i > (r); --i) #define debug(x) cerr << #x << ": " << x << endl; using namespace std; int n,s; vector<pair<int,int>> items; const int MAXS = 2005;// int dp[MAXS]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>s>>n; int v,w,k; loop(i,0,n){ cin>>v>>w>>k; int a = log2(k); loop(j,0,a){ items.push_back({(1<<j)*w,(1<<j)*v}); } int b = k-(1<<a)+1; items.push_back({b*w,b*v}); } loop(i,0,items.size()){ pool(j,s,items[i].first-1){ dp[j] = max(dp[j],dp[j-items[i].first]+items[i].second); } } cout<<dp[s]<<endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:4:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define loop(i, l, r) for(int i = (l); i < (r); ++i)
      |                                          ^
knapsack.cpp:27:5: note: in expansion of macro 'loop'
   27 |     loop(i,0,items.size()){
      |     ^~~~
#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...