Submission #826405

#TimeUsernameProblemLanguageResultExecution timeMemory
826405NoLoveKnapsack (NOI18_knapsack)C++14
73 / 100
1081 ms3924 KiB
/** * author : Lăng Trọng Đạt * created: 2023-08-15 **/ #include <bits/stdc++.h> using namespace std; #ifndef LANG_DAT #define db(...) ; #endif // LANG_DAT #define int int64_t using pii = pair<int, int>; const int MAXN = 1e5 + 5; int w[MAXN], v[MAXN], k[MAXN]; int n, s; int dp[MAXN]; int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("hi.inp", "r")) { freopen("hi.inp", "r", stdin); // freopen("hi.out", "w", stdout); } cin >> s >> n; for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } for (int i = 0; i < n; i++) { for (int x = 0; x < min(k[i], s); x++) { for (int j = s; j >= w[i]; j--) { if (j >= w[i]) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); } } } } cout << dp[s]; }

Compilation message (stderr)

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