Submission #701610

#TimeUsernameProblemLanguageResultExecution timeMemory
701610ifateenKnapsack (NOI18_knapsack)C++14
73 / 100
320 ms262144 KiB
#include <iostream> #include <vector> #include <set> #include <map> using namespace std; #define int long long #define double long double #define vec vector #define vi vec<int> #define pii pair<int,int> #define vpi vec<pii> #define MP make_pair #define PB push_back #define F first #define S second #define pq priority_queue #define all(v) v.begin(), v.end() signed main() { vi weights, vals; int W, n; cin >> W >> n; for (int i = 0; i < n; i++) { int val, weight, num; cin >> val >> weight >> num; num = min(num, W / weight + 1); for (int j = 0; j < num; j++) { weights.PB(weight); vals.PB(val); } } /* * now we solve normal knapsack */ vi dp; dp.assign(W + 1, 0); for (int i = 1; i <= weights.size(); i++) { for (int w = W; w >= 0; w--) { if (weights[i - 1] <= w) { dp[w] = max(dp[w], dp[w - weights[i - 1]] + vals[i - 1]); } } } cout << dp[W] << endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:40:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 1; i <= weights.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
#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...