# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
942466 | Sunbae | Knapsack (NOI18_knapsack) | C++17 | 71 ms | 4568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[2005];
array<int,3> Op[100005];
vector<pair<int,int>> vec[2005];
const ll inf = 1e15;
signed main(){
int S, n; scanf("%d %d", &S, &n);
vector<int>C;
for(int i = 0, Vi, Wi, Ki; i<n; ++i){
scanf("%d %d %d", &Vi, &Wi, &Ki);
Op[i] = {Vi, Wi, Ki};
C.push_back(Wi);
}
C.push_back(-1);
sort(C.begin(), C.end());
C.resize(unique(C.begin(), C.end()) - C.begin());
for(int i = 0; i<n; ++i){
int Vi = Op[i][0], Wi = Op[i][1], Ki = Op[i][2];
vec[upper_bound(C.begin(), C.end(), Wi) - C.begin() - 1].emplace_back(Vi, Ki);
}
int m = C.size();
for(int j = 1; j<=S; ++j) dp[j] = -inf;
dp[0] = 0;
for(int i = 1; i<m; ++i){
sort(vec[i].begin(), vec[i].end(), greater<pair<int,int>>());
ll w = C[i];
for(int j = S; j>=0; --j){
bool br = false;
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |