Submission #896752

#TimeUsernameProblemLanguageResultExecution timeMemory
896752blackslexKnapsack (NOI18_knapsack)C++17
100 / 100
55 ms7536 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int M = 2005;
ll n, m, dp[M];
vector<pii> u[M], t;

int main() {
    scanf("%lld %lld", &m, &n);
    vector<ll> w(n), v(n), k(n);
    for (int i = 0; i < n; i++) scanf("%lld %lld %lld", &v[i], &w[i], &k[i]), u[w[i]].emplace_back(v[i], k[i]);
    for (int i = 1; i <= m; i++) {
        ll cur = m / i;
        sort(u[i].rbegin(), u[i].rend());
        for (auto &[x, y]: u[i]) {
            ll use = min(cur, y); cur -= use;
            while (use--) t.emplace_back(x, i);
            if (!use) break;
        }
    }
    for (auto &[x, y]: t) for (int i = m; i >= y; i--) dp[i] = max(dp[i], dp[i - y] + x);
    printf("%lld", dp[m]);
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%lld %lld", &m, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:14:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for (int i = 0; i < n; i++) scanf("%lld %lld %lld", &v[i], &w[i], &k[i]), u[w[i]].emplace_back(v[i], k[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...