제출 #1147496

#제출 시각아이디문제언어결과실행 시간메모리
1147496aaa@222Knapsack (NOI18_knapsack)C++20
0 / 100
0 ms324 KiB
#include<bits/stdc++.h>
using namespace std;
#define el cout<<"\n";
#define ll long long
#define maxn 100005

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, s; cin >> n >> s;
    vector<int> w(n + 1), v(n + 1);
    vector<vector<int>> dp(n + 1, vector<int>(s + 1));
    for(int i = 1; i <= n; i++) cin >> v[i] >> w[i];
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= s; j++) dp[i][j] = max(dp[i - 1][j], (w[i] <= j) ? (dp[i - 1][j - w[i]] + v[i]) : -1);
    }
    cout << dp[n][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...