Submission #884189

#TimeUsernameProblemLanguageResultExecution timeMemory
884189fanwenKnapsack (NOI18_knapsack)C++17
100 / 100
44 ms3084 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define file(name) \ if(fopen(name".inp", "r")) \ freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); const int MAX = 2e3 + 5; int n, S; vector <pair <int, int>> weights[MAX]; int dp[MAX]; void you_make_it(void) { cin >> S >> n; memset(dp, -0x3f, sizeof dp); dp[0] = 0; for (int i = 1; i <= n; ++i) { int v, w, k; cin >> v >> w >> k; weights[w].emplace_back(v, k); } for (int i = 1; i <= S; ++i) { if(weights[i].empty()) continue; sort(weights[i].begin(), weights[i].end(), greater <pair <int, int>>()); int ind = 0; for (int j = 0; j < S / i; ++j) { if(ind >= weights[i].size()) break; for (int s = S; s >= i; --s) { dp[s] = max(dp[s], dp[s - i] + weights[i][ind].fi); } weights[i][ind].se--; if(weights[i][ind].se == 0) ind++; } } cout << *max_element(dp, dp + S + 1); } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif file("knapsack"); auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

Compilation message (stderr)

knapsack.cpp: In function 'void you_make_it()':
knapsack.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             if(ind >= weights[i].size()) break;
      |                ~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:48:5: note: in expansion of macro 'file'
   48 |     file("knapsack");
      |     ^~~~
knapsack.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:48:5: note: in expansion of macro 'file'
   48 |     file("knapsack");
      |     ^~~~
#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...