# PROBLEM LINK:

Practice

Contest: Division 1

Contest: Division 2

Contest: Division 3

* Author:* Janmansh Agarwal

*Anay Karnik*

**Tester:***Mohan Abhyas*

**Editorialist:**# DIFFICULTY:

Simple

# PREREQUISITES:

None

# PROBLEM:

You are given a sequence of integers A_1, A_2, \ldots, A_N and an integer K. Find the number of contiguous subsequences A_L, A_{L+1}, \ldots, A_R such that R-L+1 \ge K and the K-th element of the subsequence (A_{L+K-1}) is equal to the maximum of all elements of the entire sequence.

# EXPLANATION:

Let A_{max} = max(A_1,\dots,A_N)

If A_i = A_{max} number of contiguous subsequences A_L, A_{L+1}, \ldots, A_R such that R-L+1 \ge K and the K-th element of the subsequence A_{L+K-1} = A_i is N-i+1 as L = i-k+1, i \le R \le N .

Final answer is sum of number of subsequences for such A_is

# TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

# SOLUTIONS:

[details = â€śEditorialâ€™s Solutionâ€ť]

```
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,e) for(ll i = 0; i < e; i++)
void solve()
{
ll n,k;
cin>>n>>k;
vector<ll> A(n);
forn(i, n) cin>>A[i];
ll ans = 0;
ll mx = A[0];
forn(i, n)
{
mx = max(mx, A[i]);
}
for(int i = k-1; i < n; i++)
{
if(A[i] == mx)
{
ans += n-i;
}
}
cout<<ans<<endl;
}
int main()
{
ll t=1;
cin >> t;
forn(i,t) {
solve();
}
return 0;
}
```