x; } ll decrease(ll x, ll p) { ll unit = x/p; ll extra = x-unit*p; return ( (x-extra)*sq(unit) + extra*sq(unit+1)); } priority_queue< iii> pq; int main() { IOS ll n,k; cin>>n>>k; ll cost = 0; rep(i,0,n) { ll t; cin>>t; cost+=sq(t); pq.push(iii(decrease(t,1)- decrease(t,2), ii(t, 2)) ); } rep(i,0,k-n) { cost -= pq.top().fi; ll aa = pq.top().se.fi; ll bb = pq.top().se.se; pq.pop(); pq.push(iii(decrease(aa,bb) - decrease(aa,bb+1),ii( aa, bb+1))); } cout<  » 7 months ago, # | ← Rev. 4 → 0 For problem F, can someone please explain the line that updates the cur in inner loop? "cur += (l-1+x) — hist[x]" What is it exactly doing & how is it correctly updating the tot? for (int x = 1; x <= (r-l+1); ++x){ cur += (l-1+x) - hist[x]; tot += cur; hist[x] = r-x+1; } Can you please explain bensonlzl dvdg6566? •  » » 6 months ago, # ^ | +3 The variable$cur$stores the current area under the histogram and needs to be added to$tot$, which is the total sum of areas (aka the answer at the end).Here we are considering the segment of 1s from$l$to$r$inclusive. Now we consider the$x$-th one in this segment of 1s. The total area this 1 adds is the distance from itself to the last index$i$where the height of the histogram is$x$. You can look at the diagrams in the tutorial to convince yourself that this is true.Thus, we need to add$l-1+x - hist[x]$to the current area. Now if we look what the histogram looks like after we added the entire segment of ones, the$x$-th 1 from the back is at index$r-x+1$, which means that the height of the histogram at this index$(r-x+1)$after we have updated the entire segment of 1s is$x$, so we update$hist[x]$accordingly.  » 7 months ago, # | +8 I laughed out when I saw the code with language C++ for "1428E — Carrots for Rabbits". The Chinese characters in the beginning reminded me how popular the Chinese song was in the world some time ago.  » 6 months ago, # | +3 Another(probably incorrect) solution for G.Let$dp[mask][sum]$be the answer for the problem when we are allowed to use only positions from$mask$(e.g., if$mask = 100101_2$, our numbers can contain non-zero digits on positions$1, 100, 100000$).Transition for this$dp$:$dp[mask][sum] ← dp[{mask} \oplus {2^{pos}}][sum - l \cdot 10^{pos}]$, where$l$is the sum of digits, we put at position$pos$.$l_{max} = min ( 9k, \lfloor {{sum} \over {10^{pos}}}\rfloor)$is the maximum possible value of$l$. Let's iterate$l$from$l_{max} - MAGIC$to$l_{max}$.This$dp$takes$O(2^6 \cdot 6 \cdot n \cdot MAGIC)$to calculate, so let's do meet-in-the-middle: calculate$dp_1$for the lowest$3$positions and$dp_2$for the highest$3$positions. Now it takes$O(2^3 \cdot 3 \cdot n \cdot MAGIC)$to calculate.Answer for$n$is maximum of$dp_2[allPositions][i] + dp_1[allPositions][n - 10^3 \cdot i]$.Total complexity is$O(2^3 \cdot 3 \cdot n \cdot MAGIC + q \cdot 10^3)$.For some reason it passes for$MAGIC = 30$.  » 6 months ago, # | 0 Someone please explain why simple binary search doesnt work for E? I ran Binary Search on the biggest size of carrot, and for each carrot, computed how many carrots it needs to be split so that largest piece cannot be larger than mid, and then split this carrot as evenly as possible. But this is not working.The code is below: Spoiler#include using namespace std; using LL = long long; using LD = long double; const LL MOD = 1e9+7; const LL INF = LLONG_MAX; const LL N = 3e5+1; int main () { LL n, k; cin >> n >> k; vector a(n); LL mxel = 0; for (LL i = 0; i < n; ++i) { cin >> a[i]; mxel = max(mxel, a[i]); } LL low = 1, high = mxel, mid = (low+high)/2; LL minans = INF; while (low <= high) { LL cnt = 0, tot = 0; for (LL i = 0; i < n; ++i) { LL cnt1 = (a[i] + mid - 1)/mid; cnt += cnt1; LL div = a[i]/cnt1, rem = a[i]%cnt1, sm = cnt1 - rem; tot += sm*(div*div) + rem*(div+1)*(div+1); } if (cnt < k) { high = mid-1; } else if (cnt == k) { minans = min(minans, tot); high = mid-1; } else { low = mid+1; } mid = low + (high-low)/2; } cout << minans << "\n"; }  •  » » 6 months ago, # ^ | 0 Got it, its just wrong. We may also consider example case$n = 2, k = 5$,$a = [20, 60]\$ then there is no way to get all sizes less than a value x and number of pieces exactly 5.
•  » » » 6 months ago, # ^ |   0 +1 for the input.
 » 6 months ago, # | ← Rev. 3 →   0 Can anybody help me pls in problem E, I made a priority queue(max heap), and pop off the top element, and used binary search to divide that number such that it is just greater than the next lesser element. Now pushed all such divisions of this number and again used the max value and continued the process, till I get k numbers code -Submission to E problem
 » 6 months ago, # | ← Rev. 3 →   0 In 1428E, one of your test solution is probably wrong (in the 4th case my outcome is around 2*10^7 less then in the solution)
 » 6 months ago, # |   0 I love the hint part of the Editorial. Most of time I don't want to read the whole editorial to understand the details of the Solution. All I need is the key point which reminds me of the trick to solve this problem. I think it is a really nice round and editorial. Thank you guys.
 » 2 weeks ago, # |   0 that's a great tutorial,all tutorials should be written in this pattern..
 » 6 hours ago, # |   0 My solution for problem F is very different and am proud of myself to proved it, coded it up, and got it accepted! I became surprise when I saw the solution of the author.Here is my code: https://codeforces.com/contest/1428/submission/115365132.Just a short explanation of my solution: Draw a table (on a paper), where rows are the index of strings, and each column (from 0 to n) shows the number of continuous ones if we end at index r (at row r). If you fill out the table on the paper, you'll see when we have a '0' or '1' in the string, how the values for each row changes, which highly depends on the values in the previous row.
•  » » 6 hours ago, # ^ |   0 The solution runs in O(n log n) and uses segment tree + lazy propagation technique.Last week, Elle magazine, alongside The Fawcett Society and Whistles launched a feminism campaign, with celebrities such as Benedict Cumberbatch, and politicians such as Ed Miliband and Nick Clegg donning t-shirts stating ‘this is what a feminist looks like’. The Fawcett Society are the UK’s leading campaign group for women’s rights, and with such a well established fashion magazine supporting them by advertising the Whistles slogan tees in their December Feminism edition, it looked to have many people talking passionately, and engaging with the rights of women.
However, reports from the Daily Mail looked to deliver a huge blow to the campaign on Sunday, when claims were made that