一道二分题

题目:

  

Problem Description

Gashuai is a brave man live in a grand castle peacefully.However, there are many monsters want to invade the castle one day. Gashuai, the hero of the castle, want to defend the castle against monsters. The monsters comes one by one and each monster cost Gashuai a[i] HP to kill it. Gashuai has n maximum HP at first . After each fight , Gashuai can choose to reduce maximum HP by 10% and recover his current HP to maximum. To simplify this problem ,the calculation will in integer not decimal. For example , if Gashuai has 99 maximum HP , his maximum HP will reduce 99*0.1=9, and becomes 90.Of coursr, if Gashuai’s maximum HP is lower than 10, he won’t reduce maximum HP as 9*0.1=0. Gashuai’s HP shouldn’t be less than 1 after each fight. Please calculate how much HP(maximum HP) should Gashuai have before his first fight at least .Of course his current HP is same as his maximum HP before his first fight.

Input

The input contains several test cases ( no more than 20 ) , terminated by EOF.
The first line of each test contains one integers n ( 1 ≤ n ≤ 500000), indicating the number of monsters.
The second line contains n numbers and the ith number means the ith monster costs Gashuai a[i] current HP to kill it( 0 ≤ a[i] ≤ 1000).
Notice that the monsters come in order.

Output

For each test case print 1 integers in a line,indicating the initial HP Gashuai most have before the first fight.

Sample Input

3
3 2 1
8
7 4 3 8 6 5 2 7
13
1 12 5 7 11 13 7 8 9 10 10 5 13

Sample Output

4
9
25

Author

bytelin

Source

第八届浙江科技学院ACM程序设计竞赛
题目答案很简单,二分答案就可以,但是比赛的时候WA12次,我试了很多遍,赛后也问了很多大牛,都说直接二分就好,
原因就是我题意理解的太。。。。。。。。。

        Gashuai can choose to reduce maximum HP by 10% and recover his current HP to maximum

                      我理解成每次减少当前MAX_HP的10%,如果现在的HP小于这MAX_HP的10%,就OUT这种答案,

               这就是我英语渣的原因吗?

                             正解是:

                                         变化的是MAX_HP,MAX_HP每次不够时,自减10%,然后二分

                        。。。。。。。

无力吐槽了

实在是渣!!!

                                    

随性Code
原文地址:https://www.cnblogs.com/forgot93/p/3489398.html