Submission #543716

#TimeUsernameProblemLanguageResultExecution timeMemory
543716zammyKnapsack (NOI18_knapsack)C++17
0 / 100
107 ms262144 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int inf = INT_MAX, mod = 1e9 + 7, MAX_N = (1e5), MAX_S = 2000; int dp[MAX_N + 1][MAX_S + 1]; void solve() { int S, N; cin >> S >> N; vector<int> V(N + 1), W(N + 1), K(N + 1); for (int i = 1; i <= N; i++) cin >> V[i] >> W[i] >> K[i]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= S; j++) { dp[i][j] = dp[i - 1][j]; for (int k = 1; k <= K[i]; k++) { int wt = W[i] * k; if (j - wt < 0) break; dp[i][j] = max(dp[i][j], (V[i] * k) + dp[i - 1][j - wt]); } } } cout << dp[N][S] << "\n"; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed; cout << setprecision(9); int tt = 1; // cin >> tt; for (int i = 1; i <= tt; i++) { // cout << "Case #" << i << ": "; solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; }

Compilation message (stderr)

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