Chef's Candy Distribution
MediumSet by PESUECC Problem Setters
How the Arena works · Rules
Scoring, fair play, and what gets you disqualified.
How the Arena works · Rules
Scoring, fair play, and what gets you disqualified.
- 1One Problem of the Day. Read the statement on the left and solve it in the browser editor on the right.
- 2Points are awarded by speed: the faster your first Accepted submission, the higher you rank on the daily board (1000 for 1st down to 100 for 10th and beyond).
- 3The on-screen timer is only indicative — your official solve time is recorded on the server the moment your submission is Accepted.
- 4Only your first Accepted submission counts toward the leaderboard.
- 5Copy, paste and right-click are disabled inside the arena. Switching tabs or windows and taking screen captures during a live solve are recorded for review — each counts as one integrity flag.
- 6Accumulating more than 5 integrity flags (blocked paste/copy attempts, tab/window switches, screen captures) removes you from that day's top 10 — an accepted solve then earns only the 100-point base.
- 7The problem statement can't be selected or copied, it's watermarked with your identity, and it blurs when you leave the tab — leaked problems are traceable back to you.
- 8Write your own code. Plagiarism, sharing solutions, or automating submissions leads to disqualification and forfeiting the bounty.
- 9Don't probe or exploit the judge, and don't attempt to extract the hidden test cases.
Chef is handing out candies to n children standing in a line. Each child has a rating based on how well they solved today's warm-up puzzle. Chef must give out candies under two rules:
- Every child gets at least one candy.
- Any child with a strictly higher rating than an immediate neighbour must receive strictly more candies than that neighbour.
Chef is generous but not wasteful — help him find the minimum total number of candies he needs to distribute.
Input Format
- The first line contains a single integer
n— the number of children. - The second line contains
nspace-separated integersr[1], r[2], …, r[n]— the ratings of the children in line order.
Output Format
Print a single integer: the minimum number of candies Chef must distribute.
Constraints
1 ≤ n ≤ 10^50 ≤ r[i] ≤ 10^9
Sample
3 1 0 2
5
Explanation
One optimal distribution is [2, 1, 2]:
- The first child (rating
1) outranks the second (rating0), so they need more than1candy →2. - The third child (rating
2) outranks the second, so they also need2.
The total is 2 + 1 + 2 = 5, and no valid distribution uses fewer candies.
Custom inputusing sample
Run uses this input. Submit always judges the hidden tests.
Write your solution, then Run it against the sample or Submit to the judge's hidden tests. Faster accepted solves earn more of the daily bounty.
Your submissions
0 this sessionNo submissions yet — hit Submit to send your solution to the judge.
Points by finish order — the faster you get accepted, the more you earn.
Loading…