제출 #1284415

#제출 시각아이디문제언어결과실행 시간메모리
1284415zxzuamKnapsack (NOI18_knapsack)C++20
73 / 100
337 ms327680 KiB
#include <bits/stdc++.h>
#define int int64_t
using ll = int64_t;
using namespace std;
constexpr int maxn = 1E5 + 1;
void orz() {
    int s, n;
    cin >> s >> n;
    vector <int> v = {0}, w = {0};
    for(int i = 1; i <= n; i++ ){
        int V, W, K;
        cin >> V >> W >> K;
        for(int j = 1; j <= min(s, K); j++){
            v.push_back(V);
            w.push_back(W);
        }
    }
    vector <int> dp(s + 61, LLONG_MIN);
    dp[0] = 0;
    n = v.size() - 1;
    for(int i = 1; i <= n; i++) {
        for(int j = s; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    cout << *max_element(dp.begin(), dp.end());
}
int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    //freopen("promote.in", "r", stdin);
    //freopen("promote.out", "w", stdout);
    int T = 1;
    //cin >> T;
    while(T--) orz();
    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...