Submission #850462

#TimeUsernameProblemLanguageResultExecution timeMemory
850462alexz1205Knapsack (NOI18_knapsack)C++14
0 / 100
1 ms344 KiB
#include <bits/stdc++.h> using namespace std; const int S = 2000, N = 1e5; int arr[S+1]; int main() { int s, n; cin >> s >> n; set<int> weights[s+1]; for (int x = 0; x < n; x ++){ int v, w, k; cin >> v >> w >> k; k = min(k, s/w); for (int x = 0; x < k; x ++){ weights[w].insert(v); if (weights[w].size() > (s/w)){ weights[w].erase(--weights[w].end()); } } } for (int x = 1; x <= s; x ++){ for (int v: weights[x]){ for (int i = s-x; i >= 0; i --){ arr[i+x] = max(arr[i+x], arr[i]+v); } for (int i = 1; i <= s; i ++){ arr[i] = max(arr[i], arr[i-1]); } } } cout << arr[s] << endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:18:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |    if (weights[w].size() > (s/w)){
      |        ~~~~~~~~~~~~~~~~~~^~~~~~~
#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...