Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create Prog-62.cpp
  • Loading branch information
manushikapoor committed Jul 14, 2020
1 parent f2675e7 commit f2fd36f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Prog-62.cpp
@@ -0,0 +1,40 @@
/* maximum-sum-lengths-non-overlapping-subarrays-k-max-element */

#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int k,res=0;
cin>>k;
int flag=0,i=0,c=0;
while(i<n){
flag=0;
c=0;
while(a[i]<=k && i<n){
//cout<<"h";

c++;
if(a[i]==k)
flag=1;
i++;
}
if (flag==1)
res=res+c;
while(a[i]>k && i<n){
i++;
}

}
cout<<res<<endl;
}
return 0;
}

0 comments on commit f2fd36f

Please sign in to comment.