← All problemsSign in

Sereja and Shuffling

CodeChefRating 3331Open on judge ↗

Sereja have an array A = [A1, A2, ..., AN], where N is an even integer. Let the function f(A) be defined by f(A) = |(A1 + A2 + ... + AN/2) − (AN/2+1 + AN/2+2 + ... + AN)|. Sereja want to decrease the value f(A) by the unusual way. Let A[l..r] denote the sub-array [Al, Al+1, ..., Ar] of A. Sereja can shift some sub-array A[l..r], where 1 ≤ l ≤ r ≤ N, then the array A will become [A1, A2, ..., Al-1

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start