제출 #654552

#제출 시각아이디문제언어결과실행 시간메모리
654552pauloamedKnapsack (NOI18_knapsack)C++14
100 / 100
128 ms5324 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MAXN = 2010;

vector<pair<int,int>> W0[MAXN];
vector<pair<int,int>> v;

int K[MAXN];

int32_t main(){
  int S, n; cin >> S >> n;
  for(int i = 0; i < n; ++i){
    int v, w, k; cin >> v >> w >> k;
    W0[w].push_back({v, k});
  }

  for(int w = 1; w <= S; ++w){
    vector<int> tmp;
    sort(W0[w].rbegin(), W0[w].rend());

    for(auto &[x, k] : W0[w]){
      while(tmp.size() <= ((S+w-1)/w) && k--){
        tmp.push_back(x);
      }
    }

    for(auto x : tmp) v.push_back({x, w});
  }

  // cout << v.size() << "\n";

  int ans = 0;
  for(auto [x, w] : v){
    for(int i = S - w; i >= 0; --i){
      K[i + w] = max(K[i + w], K[i] + x);
      ans = max(ans, K[i + w]);
    }
  }
  cout << ans << "\n";

}

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:23:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto &[x, k] : W0[w]){
      |               ^
knapsack.cpp:24:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   24 |       while(tmp.size() <= ((S+w-1)/w) && k--){
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~
knapsack.cpp:35:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |   for(auto [x, w] : v){
      |            ^
#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...