Submission #832025

#TimeUsernameProblemLanguageResultExecution timeMemory
832025JohannDistributing Candies (IOI21_candies)C++17
29 / 100
118 ms19772 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> pii; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() int N, Q; vi C, L, R, V; vector<int> ans; std::vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { C = vi(all(c)); N = sz(c); Q = sz(l); vector<pii> cap; for (int i = 0; i < N; ++i) cap.push_back({c[i], i}); sort(all(cap)); reverse(all(cap)); vector<ll> value(1, 0); for (int q = 0; q < Q; ++q) value.push_back(value.back() + (ll)v[q]); ans.resize(N); ll ref = value.back(); ll mini = ref, maxi = ref; for (int i = sz(value) - 1; i >= 0; --i) { if (value[i] < mini) { ll maxRange = maxi - value[i]; while (!cap.empty() && cap.back().first <= maxRange) { ans[cap.back().second] = ref - (maxi - cap.back().first); cap.pop_back(); } mini = value[i]; } else if (value[i] > maxi) { ll maxRange = value[i] - mini; while (!cap.empty() && cap.back().first <= maxRange) { ans[cap.back().second] = ref - mini; cap.pop_back(); } maxi = value[i]; } } while (!cap.empty()) { ans[cap.back().second] = ref - mini; cap.pop_back(); } return ans; }
#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...