Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 1;
int n, a[N];
bool ck[N];
int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", a + i);
for(int i = 1; i < n; ++i)
ck[i] = a[i] <= 2 * a[i - 1];
int res = 0;
for(int i = 0; i < n; ++i) {
int j = i;
while(ck[j] == 1)
++j;
if(j != i) {
res = max(res, j - i);
i = j;
--i;
}
}
printf("%d\n", res + 1);
return 0;
}
Copy The Code &
Try With Live Editor
Input
10
1 2 5 6 7 10 21 23 24 49
1 2 5 6 7 10 21 23 24 49
Output
4
Demonstration
Codeforces Solution-B. Creating the Contest-Solution in C, C++, Java, Python ,Creating the Contest,Codeforces Solution