Submission #1136403

#TimeUsernameProblemLanguageResultExecution timeMemory
1136403tsengangKnapsack (NOI18_knapsack)C++20
73 / 100
1097 ms16796 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define ertunt return

int main() {
    ll s, n;
    scanf("%lld %lld", &s, &n);
    vector<pair<ll, ll>> items;
    
    for (ll i = 0; i < n; i++) {
        ll v, w, k;
        scanf("%lld %lld %lld", &v, &w, &k);
        for (ll j = 1; k > 0; j <<= 1) {
            ll take = min(j, k);
            items.pb({v * take, w * take});
            k -= take;
        }
    }

    vector<ll> dp(s + 1, 0);
    for (auto [v, w] : items) {
        for (ll j = s; j >= w; j--) {
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }

    printf("%lld", dp[s]);
    ertunt 0;
}

Compilation message (stderr)

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