Submission #652349

#TimeUsernameProblemLanguageResultExecution timeMemory
652349chanhchuong123Knapsack (NOI18_knapsack)C++14
73 / 100
1093 ms16156 KiB
#include <bits/stdc++.h> using namespace std; #define task "C" #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int S = 2020; int s, n; long long dp[S]; vector<long long> v; vector<long long> w; main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> s >> n; for (int i = 1; i <= n; i++) { int V, W, K; cin >> V >> W >> K; for (int i = 1; i <= K; i <<= 1) { K -= i; if (1LL * i * W > s) continue; v.push_back(1LL * i * V); w.push_back(1LL * i * W); } if (K) { if (1LL * K * W > s) continue; v.push_back(1LL * K * V); w.push_back(1LL * K * W); } } n = v.size(); for (int i = 0; i < n; i++) { for (int j = s; j >= 0; j--) { if (j + w[i] > s) continue; maxi(dp[j + w[i]], dp[j] + v[i]); } } cout << dp[s]; }

Compilation message (stderr)

knapsack.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main() {
      | ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     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...