Problem link: https://www.codechef.com/PPW12020/problems/ANITGUY2
DIFFICULTY:
Simple
Solution:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
cin>>t;
while(t--){
ll n,k;
cin>>k>>n;
ll arr[n];
for(int i=0;i<n;i++)cin>>arr[i];
ll product=0,p=1,l=0;
for(int i=0;i<n;i++){
p*=arr[i];
while(p>=k && l<=i){
product+=i-l;
p/=arr[l++];
}
}
p=(n-l)*(n-l+1)/2;
cout<<p+product<<"\n";
}
//code
return 0;
}
Run Time: 0.3 sec
Thanks and Regards