You are going out for a walk, when you suddenly encounterNmonsters. Each monster has a parameter calledhealth, and the health of thei-th monster ishiat the moment of encounter. A monster will vanish immediately when its health drops to0or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
- Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease byA, and the health of each of the other monsters will decrease byB. Here,AandBare predetermined parameters, andA>Bholds.
At least how many explosions do you need to cause in order to vanish all the monsters?
Constraints
- All input values are integers.
- 1≤N≤105
- 1≤B<A≤109
- 1≤hi≤109
Input
Input is given from Standard Input in the following format:
N A B h1 h2 : hN
Output
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
Sample Input 1
4 5 3 8 7 4 2
Sample Output 1
2
You can vanish all the monsters in two explosion, as follows:
- First, cause an explosion centered at the monster with8health. The healths of the four monsters become3,4,1and−1, respectively, and the last monster vanishes.
- Second, cause an explosion centered at the monster with4health remaining. The healths of the three remaining monsters become0,−1and−2, respectively, and all the monsters are now vanished.
Sample Input 2
2 10 4 20 20
Sample Output 2
4
You need to cause two explosions centered at each monster, for a total of four.
Sample Input 3
5 2 1 900000000 900000000 1000000000 1000000000 1000000000
Sample Output 3
800000000
二分啊啊啊 这么大的数 不二分怎么写
1 #include <iostream> 2 using namespacestd; 3 #include<string.h> 4 #include<set> 5 #include<stdio.h> 6 #include<math.h> 7 #include<queue> 8 #include<map> 9 #include<algorithm> 10 #include<cstdio> 11 #include<cmath> 12 #include<cstring> 13 #include <cstdio> 14 #include <cstdlib> 15 #include<stack> 16 #include<vector> 17 long long a[51000000]; 18 long longn,a1,b1; 19 long panduan(long longzhi) 20 { 21 long long t=b1*zhi; 22 long long add=0; 23 for(int i=1;i<=n;i++) 24 { 25 if(a[i]-t>0) 26 { 27 if((a[i]-t)%(a1-b1)==0) 28 add+=(a[i]-t)/(a1-b1); 29 else 30 add+=(a[i]-t)/(a1-b1)+1; 31 } 32 } 33 //cout<<zhi<<"_"<<add<<endl; 34 return add<=zhi; 35 } 36 intmain() 37 { 38 cin>>n>>a1>>b1; 39 for(int i=1;i<=n;i++) 40 scanf("%d",&a[i]); 41 long long kaishi=0,jieshu=1e9; 42 long longmid; 43 //cout<<panduan(3)<<"_"<<endl; 44 intt; 45 while(kaishi<jieshu-1) 46 { 47 //cout<<kaishi<<"_"<<jieshu<<endl; 48 mid=(jieshu+kaishi)>>1; 49 if(panduan(mid)) 50 { 51 jieshu=mid; 52 t=mid; 53 } 54 else 55 kaishi=mid; 56 } 57 cout<<jieshu<<endl; 58 return 0; 59 }