forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CODECHEF)DRCHEF
71 lines (64 loc) · 1.58 KB
/
(CODECHEF)DRCHEF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Dipesh Kumar */
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
int t;
cin >> t;
while(t--)
{
ll n, x;
cin >> n >> x;
vector<ll> a(n, 0);
for(ll i = 0; i < n; i++)
cin >> a[i];
ll d = 0;
sort(a.begin(), a.end());
vector<ll>::iterator it = lower_bound(a.begin(), a.end(), x);
ll lb = it - a.begin();
for(ll i = lb;i < n; i++)
{
if(x < a[i])
{
while(x < a[i])
{
x *= 2;
d++;
}
d++;
}
else
d++;
x = (a[i] * 2);
}
ll t = lb + d;
if(lb != 0)
{
d = 0;
lb--;
for(ll i = lb;i < n; i++)
{
if(x < a[i])
{
while(x < a[i])
{
x *= 2;
d++;
}
d++;
}
else
d++;
x = (a[i] * 2);
}
if(d + lb < t)
cout << d + lb;
else
cout << t;
}
else
cout << lb + d;
cout<< endl;
}
return 0;
}