제출 #1130502

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

using namespace std;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(0);

    
    int K{}, M{};
    cin >> K >> M;
    vector<int> w(M+1);
    vector<int> p(M+1);
    w[0] = p[0] = 0;
    for (int i = 1; i <= M; i++) {
        cin >> w[i] >> p[i];
    }
    vector<vector<int>> dp(M+1, vector<int>(K+1, 0));
    for (int i = 1; i <= M; i++) {
        for (int j = 1; j <= K; j++) {
            if (j >= w[i])
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + p[i]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[M][K] << "\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...