Submission #636141

#TimeUsernameProblemLanguageResultExecution timeMemory
636141TUNGDUONGWILLWINVOI2023Knapsack (NOI18_knapsack)C++14
73 / 100
637 ms262144 KiB
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
const int NAXM = 2e3 + 5;
int S, N, dp[NAXM];
vector<array<int, 2>> a;
int main() {
  // Coding
  scanf("%d%d", &S, &N);
  for (int i = 0; i < N; ++i) {
    int v, w, k;
    scanf("%d%d%d", &v, &w, &k);
    for (int j = 0; j < min(k, S / w + 1); ++j) {
      a.push_back({v, w});
    }
  }
  int L = int(a.size());
  for (int i = 0; i < L; ++i) {
    for (int j = S; j >= 0; --j) {
      if (j + a[i][1] <= S) {
        dp[j + a[i][1]] = max(dp[j + a[i][1]], dp[j] + a[i][0]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= S; ++i) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d%d", &S, &N);
      |   ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d%d", &v, &w, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...