Submission #828853

#TimeUsernameProblemLanguageResultExecution timeMemory
828853raphaelpKnapsack (NOI18_knapsack)C++14
100 / 100
105 ms7960 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; cin >> S >> N; vector<vector<int>> Tab(N, vector<int>(3)); for (int i = 0; i < N; i++) { cin >> Tab[i][0] >> Tab[i][1] >> Tab[i][2]; } sort(Tab.begin(), Tab.end()); vector<vector<int>> Val(S + 1); for (int i = N - 1; i >= 0; i--) { while (Tab[i][2] && Val[Tab[i][1]].size() * Tab[i][1] <= S) { Val[Tab[i][1]].push_back(Tab[i][0]); Tab[i][2]--; } } vector<int> dp(S + 1); for (int i = 1; i <= S; i++) { for (int j = 0; j < Val[i].size(); j++) { for (int k = S - i; k >= 0; k--) { dp[k + i] = max(dp[k + i], dp[k] + Val[i][j]); } } } int ans = 0; for (int i = 0; i <= S; i++) { ans = max(ans, dp[i]); } cout << ans; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:63: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |         while (Tab[i][2] && Val[Tab[i][1]].size() * Tab[i][1] <= S)
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
knapsack.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int j = 0; j < Val[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~~~
#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...