제출 #1147107

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

int main() {
    long long s, n;
    cin >> s >> n;
    
    vector<tuple<long long, long long, long long>> in(n);
    
    for (int i = 0; i < n; i++) {
        long long v, w, z;
        cin >> v >> w >> z;
        in[i] = {v, w, z};
    }
    
    vector<vector<long long>> dp(s + 1, vector<long long>(n + 1, 0));

    for (int j = 1; j <= n; j++) {
        auto [v, w, z] = in[j - 1];
        for (int i = 0; i <= s; i++) {
            if (w <= i) {
                dp[i][j] = max(dp[i][j - 1], dp[i - w][j - 1] + v);
            } else {
                dp[i][j] = dp[i][j - 1];
            }
        }
    }

    cout << dp[s][n] << endl;
}
#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...