Candies on a Tree
CodeChefOpen on judge ↗
There’s a tree with $N$ vertices where each of the vertices have some candies. Chandra is a greedy boy and wants to get as many candies as possible on his walk. However, he will only take candies from a node if the current node has strictly more candies than the previous node he emptied. Help him choose two nodes so that he collects the maximum number of candies. Chandra defines a walk as follow
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