Submission #932234

#TimeUsernameProblemLanguageResultExecution timeMemory
932234RegulusKnapsack (NOI18_knapsack)C++17
73 / 100
35 ms10592 KiB
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0); #define debug(x) cerr << #x << " = " << (x) << ' ' #define bug(x) cerr << (x) << ' ' #define endl cerr << '\n' #define all(v) (v).begin(), (v).end() #define SZ(v) (ll)(v).size() #define lowbit(x) (x)&-(x) #define pb emplace_back #define F first #define S second using namespace std; using ll = long long; using pll = pair<ll, ll>; //#define TEST const int N = 1e5+5; ll wei[N], val[N], num[N], dp[2005], sum[N]; vector<int> v[2005], com; int main(void) { IO int n, i, T; cin >> T >> n; for (i=1; i <= n; ++i) cin >> val[i] >> wei[i] >> num[i], v[wei[i]].pb(i); for (i=1; i <= 2000; ++i) { if (v[i].empty()) continue; com.clear(); for (int x : v[i]) com.pb(val[x]); sort(all(com)); com.resize(unique(all(com))-com.begin()); for (int j=0; j < SZ(com); ++j) sum[j] = 0; for (int x : v[i]) { auto it = lower_bound(all(com), val[x]) - com.begin(); sum[it] += num[x]; } int tot = 0; for (int t=SZ(com)-1; t >= 0; --t) { tot += sum[t]; if (tot > T/i) sum[t] -= tot - T/i; for (int j=1; sum[t] > 0; j <<= 1) { int tmp = min((ll)j, sum[t]); sum[t] -= tmp; for (int k=T; k >= tmp*i; --k) { dp[k] = max(dp[k], dp[k-tmp*i] + com[t]*tmp); } } if (tot > T/i) break; } } cout << dp[T] << '\n'; return 0; }
#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...