Submission #581959

#TimeUsernameProblemLanguageResultExecution timeMemory
581959BelguteiKnapsack (NOI18_knapsack)C++17
100 / 100
66 ms2896 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int s,n; ll val, wei, num; vector<pair<ll,ll>> p[2005]; vector<ll> v[2005]; ll dp[2005]; ll ans; int main() { IOS cin >> s >> n; // s <= 2000 for(int i = 1; i <= n; i ++) { cin >> val >> wei >> num; p[wei].pb({-val, num}); } for(int i = 1; i <= s; i ++) { sort(p[i].begin(), p[i].end()); int tmp = s / i; int pos = 0; while(tmp > 0 && pos < p[i].size()) { if(p[i][pos].ss == 0) { pos ++; continue; } tmp --; v[i].pb(-p[i][pos].ff); p[i][pos].ss --; } } for(int i = 1; i <= s; i ++) { // weight for(int j = s; j >= 0; j --) { ll tmp = 0; for(int k = 0; k < v[i].size(); k ++) { if(j - (k + 1) * i < 0) break; tmp += v[i][k]; dp[j] = max(dp[j], dp[j - (k + 1) * i] + tmp); ans = max(ans, dp[j]); } } } cout << ans; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:28:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         while(tmp > 0 && pos < p[i].size()) {
      |                          ~~~~^~~~~~~~~~~~~
knapsack.cpp:41:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for(int k = 0; k < v[i].size(); 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...