Submission #1146423

#TimeUsernameProblemLanguageResultExecution timeMemory
1146423CrabCNHKnapsack (NOI18_knapsack)C++20
100 / 100
38 ms3056 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) using namespace std; template <class T> void mini (T &t, T f) {if (t > f) t = f;} template <class T> void maxi (T &t, T f) {if (t < f) t = f;} const int maxN = 1e5 + 5; const int maxS = 2e3 + 5; const int inf = 1e18 + 7; const int mod = 1e9 + 7; vector <pii> a[maxS]; int dp[maxN]; void solve () { int n, S; cin >> S >> n; for (int i = 1; i <= n; i ++) { int v, w, k; cin >> v >> w >> k; a[w].push_back ({v, k}); } for (int w = 1; w <= S; w ++) { if (a[w].size () >= 1) { sort (a[w].rbegin (), a[w].rend ()); } } for (int w = 1; w <= S; w ++) { int cnt = 0; for (auto [v, k] : a[w]) { for (int curK = 1; curK <= k && curK * w <= S; curK ++) { for (int j = S; j >= w; j -- ) { maxi (dp[j], dp[j - w] + v); } } cnt += k; if (cnt > S / w) { break; } } } int res = 0; for (int i = 1; i <= S; i ++) { maxi (res, dp[i]); } cout << res; } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { solve (); } return 0; } // thfdgb

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:63:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:64:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         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...