Skip to content

Commit e2091f2

Browse files
committed
1351
1 parent b69f1b5 commit e2091f2

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
int n,k,q;
12+
cin>>n>>k>>q;
13+
vector<long long> v(n);
14+
for(int i=0;i<n;i++){
15+
cin>>v[i];
16+
}
17+
long long count=0,maxo=0,ans=0;
18+
for(int i=0;i<n;i++){
19+
if(max(maxo,v[i])<=q){
20+
count++;
21+
maxo=max(maxo,v[i]);
22+
}
23+
else{
24+
if(count>=k){
25+
long long temp1=count-k+1;
26+
long long temp2=(temp1*(temp1+1))/2;
27+
ans+=temp2;
28+
}
29+
count=0,maxo=0;
30+
if(v[i]<=q){
31+
maxo=v[i];
32+
count=1;
33+
}
34+
}
35+
}
36+
if(count>=k){
37+
long long temp1 = count - k+1;
38+
long long temp2 = (temp1 * (temp1 + 1)) / 2;
39+
ans += temp2;
40+
}
41+
cout<<ans<<endl;
42+
return 0;
43+
}
44+
int main()
45+
{
46+
int testCase=1;
47+
cin>>testCase;
48+
while(testCase--){
49+
solve();
50+
}
51+
return 0;
52+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll;
6+
const ll INF = 1e18;
7+
const ll mod1 = 1e9 + 7;
8+
const ll mod2 = 998244353;
9+
// Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int countNegatives(vector<vector<int>> &grid)
15+
{
16+
int cnt = 0;
17+
int n = grid.size();
18+
int m = grid[0].size();
19+
int column = n - 1, row = 0;
20+
while (row < m && column >= 0)
21+
{
22+
if (grid[column][row] < 0)
23+
{
24+
cnt += (m - row);
25+
column--;
26+
}
27+
else
28+
row++;
29+
}
30+
return cnt;
31+
}
32+
};

0 commit comments

Comments
 (0)