Submission #1097390

#TimeUsernameProblemLanguageResultExecution timeMemory
1097390NEMO_Knapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector<pair<long long, long long>> vii;
 
#define pb push_back
#define all(x) x.begin(), x.end()
 
const int V = 1e6 + 7;
const int N = 1e5 + 7;
const int S = 2e3 + 7;
const int inf = 1e9;
 
long long s, n, v[N], w[N], k[N];
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
  // freopen("test.inp", "r", stdin);
  //freopen("test.out", "w", stdout);
  #endif
  cin >> s >> n;
  for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i];
 
  if (1 <= n && n <= 1e5 && mx <= 1e9) {
    vii obj[S];
    long long dp[2001];
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= n; i++) {
      obj[w[i]].pb({v[i], k[i]});
    }
 
    for (int i = 0; i <= s; i++) {
      if (obj[i].size() == 0) continue;
      sort(all(obj[i]), greater<pair<int, int>>());
 
      int id = 0;
      for (int j = 0; j * i < s; j++) {
        if (id >= obj[i].size()) break;
        for (int k = s; k >= i; k--) {
          dp[k] = max(dp[k], dp[k - i] + obj[i][id].first);
        }
        --obj[i][id].second;
        if (obj[i][id].second == 0) ++id;
      }
    }
    cout << dp[s] << endl;
  } 
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:29: error: 'mx' was not declared in this scope
   27 |   if (1 <= n && n <= 1e5 && mx <= 1e9) {
      |                             ^~
knapsack.cpp:41:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if (id >= obj[i].size()) break;
      |             ~~~^~~~~~~~~~~~~~~~