Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).
Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty (no matter on what online judge was it).
Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.
With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.
For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.
Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.
Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
3 3 2 1 9
1
4 20 10 3 6 3
0
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second example he can solve every problem right from the start.
题目大意:
现在有N个问题,已知之前已经最难做到了难度为K的题,现在我们如果想要做一个题,我们可以做K*2>=a[i]的题,每次做完难题之后,更新K值。
我们现在可以在其他OJ上做题,来提升自己的实力,问做完这N个题最少需要在其他OJ做几个题。
思路:
将问题贪心的从小到大排序,对应扫一遍,能够做的做了,然后更新难度,否则在其他OJ做一个K*2难度的题即可。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll __int64
ll a[15000];
int main()
{
ll n,k;
while(~scanf("%I64d%I64d",&n,&k))
{
ll output=0;
for(ll i=1;i<=n;i++)scanf("%I64d",&a[i]);
sort(a+1,a+1+n);
for(ll i=1;i<=n;i++)
{
if(a[i]<=k*2)
{
k=max(k,a[i]);
continue;
}
else
{
output++;
k*=2;
i--;
}
}
printf("%I64d\n",output);
}
}