Submission #1003131

#TimeUsernameProblemLanguageResultExecution timeMemory
1003131fryingducKnapsack (NOI18_knapsack)C++17
100 / 100
292 ms5108 KiB
// #pragma GCC optimize("Ofast,unroll-loops") #include "bits/stdc++.h" using namespace std; #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define yes cout << "YES\n" #define no cout << "NO\n" #ifdef LOCAL #define debug(val) cerr << "["#val << " = " << (val) << "] " #define slash() cerr << "\n-----------\n" #define time() cerr << "Time is: " << 1000 * clock()/CLOCKS_PER_SEC << " ms\n" #else #define debug(val) 1407 #define slash() 1407 #define time() 1407 #endif const string filename = ""; void IO(){ ios_base::sync_with_stdio(0); cin.tie(0); if(filename.size()){ string in = filename + ".inp"; string out = filename + ".out"; freopen(in.c_str(), "r", stdin); freopen(out.c_str(), "w", stdout); } } int n, W; vector<pair<long long, long long>> item[2005]; long long f[2005]; void solve(){ cin >> W >> n; for(int i=0;i<n;i++){ int v, w, k; cin >> v >> w >> k; item[w].push_back({v, k}); } for(int i = 1; i <= W; ++i) { sort(item[i].begin(), item[i].end(), greater<pair<int, int>>()); for(int j = W; j >= 0; --j) { int cur = 0; long long sum = 0; for(int k = 0; k < (int)item[i].size(); ++k) { for(int l = 0; l < item[i][k].second; ++l) { ++cur; sum = sum + item[i][k].first; if(j < cur * i) break; f[j] = max(f[j], f[j - cur * i] + sum); } } } } cout << *max_element(f + 1, f + W + 1); } signed main(){ IO(); int test = 1; /* cin >> test; */ for(int i=1;i<=test;i++){ // cout << "Case " << "#" << i << ": "; solve(); } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void IO()':
knapsack.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen(in.c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(out.c_str(), "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...