Submission #1086687

#TimeUsernameProblemLanguageResultExecution timeMemory
1086687quangminh412Knapsack (NOI18_knapsack)C++14
73 / 100
467 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long const int maxn = 1e5 + 9; ll s; int n; ll v[maxn], w[maxn], k[maxn]; int main() { if (fopen("BALO.INP", "r")) { freopen("BALO.INP", "r", stdin); freopen("BALO.OUT", "w", stdout); } faster(); cin >> s >> n; for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i]; ll ans = 0; vector<vector<ll>> dp(n + 5, vector<ll>(s + 5, 0)); for (int i = 1; i <= n; i++) { for (int j = 0; j <= s; j++) { dp[i][j] = dp[i - 1][j]; for (int c = 1; c <= min(s / w[i], k[i]); c++) if (j >= c * w[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - c * w[i]] + c * v[i]); if (i == n) ans = max(ans, dp[i][j]); } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

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