Submission #1324028

#TimeUsernameProblemLanguageResultExecution timeMemory
1324028sh_qaxxorov_571Knapsack (NOI18_knapsack)C++20
73 / 100
1093 ms444 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int S, N;
    cin >> S >> N;

    vector<long long> dp(S + 1, 0);

    for (int i = 0; i < N; i++) {
        long long V, W, K;
        cin >> V >> W >> K;

        // Binary splitting
        long long count = 1;
        while (K > 0) {
            long long take = min(count, K);
            long long weight = take * W;
            long long value = take * V;

            for (int j = S; j >= weight; j--) {
                dp[j] = max(dp[j], dp[j - weight] + value);
            }

            K -= take;
            count <<= 1;
        }
    }

    cout << dp[S] << "\n";

    return 0;
}
#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...