🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"KMAX2","problem_name":"K-th Maximum","problemComponents":{"constraints":"- $1 \\le T \\le 200$\n- $1 \\le K \\le N \\le 2 \\cdot 10^5$\n- $|A_i| \\le 10^5$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^5$","constraintsState":true,"subtasks":"**Subtask #1 (10 points)**\n- $T \\le 10$\n- $N \\le 100$\n\n**Subtask #2 (90 points)** original constraints\n","subtasksState":true,"inputFormat":"- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N$ and $K$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.\n","inputFormatState":true,"outputFormat":"For each test case, print a single line containing one integer --- the number of contiguous subsequences satisfying the given conditions.\n","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"1\n5 3\n1 2 3 4 5","output":1,"explanation":"**Example case 1:** $(3, 4, 5)$ is the only contiguous subsequence such that its $3$-rd element is equal to the maximum of the whole sequence (which is $5$).","isDeleted":false}}},"video_editorial_url":"https://youtu.be/soDl9BXCJ-s","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":0.5,"source_sizelimit":50000,"problem_author":"janmansh","problem_tester":"","date_added":"24-08-2021","tags":{"0":"janmansh","1":"ltime99","2":"simple"},"problem_difficulty_level":"Simple","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/KMAX2","time":{"view_start_date":1630170002,"submit_start_date":1630170002,"visible_start_date":1630170002,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=KMAX2","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Mandarin](https://www.codechef.com/download/translated/LTIME99/mandarin/KMAX2.pdf), [Russian](https://www.codechef.com/download/translated/LTIME99/russian/KMAX2.pdf), and [Vietnamese](https://www.codechef.com/download/translated/LTIME99/vietnamese/KMAX2.pdf) as well.

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.

<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>