제출 #1151327

#제출 시각아이디문제언어결과실행 시간메모리
1151327jeffffKnapsack (NOI18_knapsack)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

struct p{
    int v, w;
} c[300010];

long long S, N, v, w, k, n1 = 1, f[300010];


int main () {
    cin >> S >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> v >> w >> k;
        int t = 1;
        while (k >= t){
            c[++n1].v = v*t;
            c[n1].w = w*t;
            k -= t;
            t *= 2;
        }
        if (k > 0) {
            c[++n1].v = v*k;
            c[n1].w = w*k;
        }
    }
    for (int i = 1; i <= n1; ++i) {
        for (int j = S; j >= c[i].w; --j) {
            f[j] = max(f[j - 1], f[j - c[i].w] + c[i].v);
        }
    }
    cout << f[S];
}
#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...