Submission #886380

#TimeUsernameProblemLanguageResultExecution timeMemory
886380Zero_OPKnapsack (NOI18_knapsack)C++14
100 / 100
220 ms3920 KiB
#include<bits/stdc++.h> using namespace std; #define range(v) begin(v), end(v) #define compact(v) v.erase(unique(range(v)), end(v)) template<class T> bool minimize(T& a, T b){ if(a > b) return a = b, true; return false; } template<class T> bool maximize(T& a, T b){ if(a < b) return a = b, true; return false; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; int S, n; void Zero_OP(){ cin >> S >> n; vector<pair<ll, int>> items; vector<vector<pair<int, int>>> block(S + 1); while(n--){ int v, w, k; cin >> v >> w >> k; block[w].push_back({v, k}); } vector<ll> dp(S + 1, -1e18); dp[0] = 0; for(int i = 1; i <= S; ++i){ if(block[i].empty()) continue; sort(range(block[i]), greater<pair<int, int>>()); for(int w = S; w >= 0; --w){ int curW = 0, curV = 0; for(int j = 0; j < block[i].size(); ++j){ for(int k = 1; k <= block[i][j].second and curW <= S; ++k){ curW += i; curV += block[i][j].first; if(w >= curW){ maximize(dp[w], dp[w - curW] + curV); } } } } } cout << *max_element(range(dp)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define task "antuvu" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } Zero_OP(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void Zero_OP()':
knapsack.cpp:43:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       for(int j = 0; j < block[i].size(); ++j){
      |                      ~~^~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen(task".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...