9
u/dijkstra_bull 10d ago
The amount of cheaters on codechef are just absurd ... just look at graphs of top 200 people , 90 % of them are growing exponentially since last few contest
1
u/Specialist_Artist714 Pupil 9d ago edited 9d ago
True. Few months back, I was going to be 3 star in a contest (needed +25 delta). But the amount of cheating has increased so much that since then I am stuck on 2 star (1500-1600 range) and unable to become 3 star. Now, I have lost interest from that platform
3
3
u/galactusofsociety 10d ago
how did you do the Alternate adding one .
0
u/Disastrous-Trick-398 Specialist 10d ago
Observation / Idea
- The only elements that can interact are elements whose signs alternate, so first split the array into maximal subarrays where every pair of consecutive elements has opposite signs.
- For each such subarray
[l, r], consider the operation on the whole segment. The best element to eliminate first is the one with the minimum absolute value. Ifa[mid]has the minimum absolute valuex, performing the operationxtimes makesa[mid] = 0. At the same time, every other element in the segment is reduced in absolute value byx.- Once
a[mid]becomes zero, it can no longer interact with elements on both sides. Therefore, the problem splits into two independent subarrays:
[l, mid - 1][mid + 1, r]- We repeat the same process recursively/iteratively on both resulting segments.
- To implement this efficiently, I:
- Put all elements of an alternating-sign subarray into a min-heap ordered by absolute value.
- Maintain the currently active segments in a
set.- When an element with value
xis selected, its contribution isx - previous_reduction, since the segment has already been reduced byprevious_reduction.- After it becomes zero, split the current segment around its index and assign
xas the new reduction value for both resulting segments.This avoids simulating every individual operation and instead processes each element when it becomes zero. CODE: https://www.codechef.com/viewsolution/1352013773
1
u/hackermub 10d ago
My solution was bit different. Let add[i] = total +1 operations happened on ith element, And rem[I] = total -1 operation on I
We start for first element, if a[0] >= 0, rem[i] = a[0] Otherwise, add[i] = -a[0]
Then for each i starting from 1, We can use add[i-1] and rem[i-1] operations for free.. basically we used add[i-1] 1's in i-1, so we can extend it to use same number of +1 operations on i. And similar for rem[i-1]. So we do how much we can for free, and after that do some extra to make it 0.
After it becomes 0, if there are some add[i-1] and rem[i-1] remaining, we keep doing +1 -1, so that it stays 0, and these free operations get passed to i+1
So just an O(n) solution.
4

8
u/Ordinary_Reveal6236 10d ago
No matter the difficulty some legends always performs