Submission #1092567

#TimeUsernameProblemLanguageResultExecution timeMemory
1092567AryanPadarthiKnapsack (NOI18_knapsack)C++11
0 / 100
1094 ms884 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int main() { int w; int n; int mval=0; int bob; cin >> w >> n; vector<int> points(n); vector<int> weight(n); vector<int> count(n); vector<int> useful; for (int i = 0; i < n; i++){ cin >> points[i] >> weight[i] >> count[i]; } vector<int> dp(w+1,0); //dp[0]=1; for (int i = 0; i < n; i++){ for (int j = 0; j < count[i]; j++){ bob= useful.size(); for (int k = useful.size()-1; k >-1 ; k--){ if (dp[useful[k]] > 0){ if (useful[k]+weight[i]<dp.size()){ dp[useful[k]+weight[i]] = max(dp[useful[k]+weight[i]],dp[useful[k]] + points[i]); useful.push_back(useful[k]+weight[i]); } useful.erase(unique(useful.begin(), useful.end()), useful.end()); } } if (j==0){ dp[weight[i]] = max(dp[weight[i]],points[i]); useful.push_back(weight[i]); useful.erase(unique(useful.begin(), useful.end()), useful.end()); } } } for (int i = 0; i < dp.size(); i++){ if (dp[i]>mval){ mval = dp[i]; } } cout << mval; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:31:29: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |      if (useful[k]+weight[i]<dp.size()){
knapsack.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for (int i = 0; i < dp.size(); i++){
      |                  ~~^~~~~~~~~~~
knapsack.cpp:11:6: warning: variable 'bob' set but not used [-Wunused-but-set-variable]
   11 |  int bob;
      |      ^~~
#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...