Submission #464295

#TimeUsernameProblemLanguageResultExecution timeMemory
464295vbeeKnapsack (NOI18_knapsack)C++14
100 / 100
71 ms4820 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ii pair<int,int> #define vii vector<ii> #define vi vector<int> #define fi first #define se second #define TASK "" #define ll long long #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define pb push_back #define MASK(i) (1 << (i)) #define BIT(x, i) ((x >> (i)) & 1) using namespace std; const int oo = 1e9 + 7; const ll loo = (ll)1e18 + 7; const int N = 1e5 + 1; const int S = 2007; int dp[S], w[N], v[N], k[N], n, s; void maximize(int &a, int b){ if (a < b) a = b; } vii obj[S]; int main() { scanf("%d%d", &s, &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &v[i], &w[i], &k[i]); obj[w[i]].pb({v[i], k[i]}); } for (int i = 0; i <= s; i++){ if (obj[i].size() == 0) continue; sort(all(obj[i]), greater<ii>()); int id = 0; for (int j = 0; j * i < s; j++){ if (id >= obj[i].size()) break; for (int k = s; k >= i; k--){ maximize(dp[k], dp[k - i] + obj[i][id].fi); } if (--obj[i][id].se == 0) id++; } } cout << dp[s]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:40:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |    if (id >= obj[i].size()) break;
      |        ~~~^~~~~~~~~~~~~~~~
knapsack.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d%d", &s, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%d%d%d", &v[i], &w[i], &k[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...