답안 #470667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470667 2021-09-04T19:05:31 Z Darthspartan Knapsack (NOI18_knapsack) C++17
0 / 100
117 ms 262148 KB
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

vector<int> value;
vector<int> weight;
vector<int> copies;
vector<int> ans (4e3+4,-1);
vector<vector<int>> copiesdp(1e5+5, vector<int>(4e3+3));

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, x;
    cin >> x >> n;

    for(int i=0;i<n;i++){
        int a,b,c;
        cin >> a >> b >> c;
        value.push_back(a);
        weight.push_back(b);
        copies.push_back(c);
    }

    ans[0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=x;j++){
            if(copiesdp[i][j]==copies[i])
                continue;

            if(ans[j+weight[i]]<=ans[j]+value[i]){
                ans[j+weight[i]]=ans[j]+value[i];
                copiesdp[i][j+weight[i]]=copiesdp[i][j]+1;
            }
        }
    }

    cout << *(max_element(ans.begin(),ans.begin()+x+1));
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 117 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 115 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 115 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 117 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 117 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -