Submission #1006328

#TimeUsernameProblemLanguageResultExecution timeMemory
1006328DaciejMaciejKnapsack (NOI18_knapsack)C++17
100 / 100
39 ms1716 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef vector<char> VC; typedef vector<vector<char>> VVC; typedef vector<bool> VB; typedef vector<vector<bool>> VVB; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<pair<int, int>> VPI; typedef vector<pair<long long, long long>> VPL; #define LINE '\n' #define SPACE ' ' #define PB push_back #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() // static const ll MOD = 998244353; ll binpow(ll a, ll b, ll mod) { ll res = 1; while (b > 0) { if (b & 1) { res = (res * a) % mod; } a = (a * a) % mod; b >>= 1; } return res; } void solve() { int s, n; cin >> s >> n; vector<VPI> vec(s + 1); FOR(i, 0, n) { int v, w, k; cin >> v >> w >> k; vec[w].PB({v, k}); } VL dp(s+1); FOR(i, 1, s + 1) { sort(RALL(vec[i])); int ct = s / i; for(auto [v, k] : vec[i]) { bool changed = false; while(ct > 0 && k > 0) { for(int j = s; j-i >= 0; j--) { ll prev = dp[j]; dp[j] = max(dp[j], dp[j-i] + ll(v)); changed |= prev != dp[j]; } ct--; k--; } if(!changed) break; if(ct <= 0) break; } } cout << *max_element(ALL(dp)) << LINE; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while (t--) solve(); }
#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...