Submission #601882

#TimeUsernameProblemLanguageResultExecution timeMemory
601882SeDunionDistributing Candies (IOI21_candies)C++17
0 / 100
5029 ms7044 KiB
#include "candies.h" #include<algorithm> #include<iostream> #include <vector> using namespace std; using vi = vector<int>; vi distribute_candies(vi c, vi l, vi r, vi v) { const int inf = 1e9; int n = c.size(); int q = l.size(); vector<int>ans; vector<int>vec; for (int i = 0 ; i < n ; ++ i) { vec = {c[i]+2, 0}; for (int j = 0 ; j < q ; ++ j) { if (l[j] <= i && i <= r[j]) { vec.emplace_back(vec.back() + v[j]); } } int m = (int)vec.size() - 1; int l = 0, r = m; while (l < r) { int k = (l + r) >> 1; int mx = -inf, mn = inf; for (int j = k ; j <= m ; ++ j) { mx = max(mx, vec[j]); mn = min(mn, vec[j]); } if (mn >= vec[k] && mx <= vec[k] + c[i]) { r = k; } else { l = k + 1; } } int s; if (vec[r] >= vec[r - 1]) s = vec[r] - c[i]; else s = vec[r]; ans.emplace_back(vec.back() - s); } 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...