Submission #918880

#TimeUsernameProblemLanguageResultExecution timeMemory
918880imannKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <iostream> typedef long long ll; const int MAX_N = 1000*100 + 10; const int MAX_S = 2*1000 + 10; ll Vs[MAX_N]; ll Ws[MAX_N]; ll Ks[MAX_N]; std::pair<ll, ll> dp[MAX_N][MAX_S]; int solve(int s, int n) { for (int i = 0; i <= s; ++i) { ll c = std::min(Ks[0], i / Ws[0]); dp[0][i] = {c * Vs[0], i - c * Ws[0]}; } for (int i = 1; i < n; ++i) { for (int j = 0; j <= s; ++j) { ll c = std::min(Ks[i], j / Ws[i]); ll v = c * Vs[i]; ll c2 = std::min(Ks[i], dp[i - 1][j].second / Ws[i]); ll v2 = c2 * Vs[i]; if (dp[i - 1][j].first + v2 >= dp[i - 1][j - c * Ws[i]].first + v) { dp[i][j] = {dp[i - 1][j].first + v2, dp[i - 1][j].second - c2 * Ws[i]}; } else { dp[i][j] = {dp[i - 1][j - c * Ws[i]].first + v, dp[i - 1][j - c * Ws[i]].second}; } } } return dp[n - 1][s].first; } int main() { int s, n; std::cin >> s >> n; for (int i = 0; i < n; ++i) std::cin >> Vs[i] >> Ws[i] >> Ks[i]; std::cout << solve(s, n) << std::endl; }

Compilation message (stderr)

/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status