Friends and Candies
Hasan is preparing a party for his $M$ friends (numbered $1$ through $M$). He bought $N$ baskets of candies (numbered $1$ through $N$); for each valid $i$, the $i$-th basket contains $a_i$ candies. Each friend should get at most one candy. For each valid $i$, the $i$-th friend would like to get a candy either from one of the first $L_i$ baskets or one of the last $R_i$ baskets, i.e. a from basket
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.
Sign in to chat with the tutor and save your progress.
Sign in to start