Codeforces Round #318 [Russiancodecup Thanks-round] (Div. 2) A. Bear and Elections (priority queue)

Source: Internet
Author: User

Limak is a grizzly bear who desires power and adoration. He wants to win on upcoming elections and rule over the Bearland.

There isNCandidates, including Limak. We know how many citizens is going to vote for each candidate. NowI-th candidate would get ai Votes. Limak is candidate number1. To win in elections, he must get strictly more votes than any other candidate.

Victory is more important than everything else so Limak decided to cheat. He'll steal votes from the He opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy-citizens is bears and bears like candies. Limak doesn ' t have many candies and wonders-how many citizens does he has to bribe?

Input

The first line contains a single integer n (2?≤? N? ≤?100)-Number of candidates.

The second line containsNspace-separated integers a1,? a 2,?...,? a N (1?≤? a i? ≤?1000)-Number of votes for each candidate. Limak is candidate number1.

Note that after bribing number of votes for some candidate might is zero or might be greater than .

Output

Print the minimum number of citizens Limak must bribe to has strictly more votes than any other candidate.

Sample Test (s) input
55 1 11) 2 8
Output
4
Input
41 8 8 8
Output
6
Input
27 6
Output
0
Note

In the first sample Limak have5Votes. One of the ways to achieve victory are to bribe4Citizens want to vote for the third candidate. Then numbers of votes would be9,?1,?7,?2,?8(Limak would has9Votes). Alternatively, Limak could steal only3Votes from the third candidate and1Vote from the second candidate to get situation9,?0,?8,?2,?8.

In the second sample Limak would steal 2 votes from each candidate. Situation'll be 7,?6,?6,?6.

In the third sample Limak are a winner without bribing any citizen.

At that time,--= thought it would time out






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round #318 [Russiancodecup Thanks-round] (Div. 2) A. Bear and Elections (priority queue)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.