Problem:
Score : 700 points

Problem Statement

Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).

Now, he will perform the following operation exactly once:

Choose K consecutive elements in P and sort them in ascending order.

Find the number of permutations that can be produced as P after the operation.

Constraints

2 \leq N \leq 200000

2 \leq K \leq N

0 \leq P_i \leq N-1

P_0,P_1,\cdots,P_{N-1} are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_0 P_1 \cdots P_{N-1}

Output

Print the number of permutations that can be produced as P after the operation.

Sample Input 1

5 3
0 2 1 4 3

Sample Output 1

2

Two permutations can be produced as P after the operation: (0,1,2,4,3) and (0,2,1,3,4).

Sample Input 2

4 4
0 1 2 3

Sample Output 2

1

Sample Input 3

10 4
2 0 1 3 7 5 4 6 8 9

Sample Output 3

6

Solution in C (Clang 3.8.0) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int n, k;
	long int count = 0;
	long int max, min;
	long int index_max, index_min;
	long int work;
	long int p[200000] = {0};
	
	scanf("%ld%ld", &n, &k);
	
	max = 0;
	min = n;
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &p[i]);
	}
	
	for(i = 0; i < k; i++) {
		if(p[i] > max) {
			max = p[i];
			index_max = i;
		}
		if(p[i] < min) {
			min = p[i];
			index_min = i;
		}
	}
	
	count = 1;
	
	work = p[0];
	
	for(i = 1; i < k; i++) {
		if(work > p[i]) {
			//count = 0;
			break;
		}
		work = p[i];
	}
	
	
	for(i = k; i < n; i++) {
		if( (index_min == i - k) && (max < p[i]) ) {
			;
		} else {
			count++;
		}
		min = 200000;
		for(j = 0; j < k; j++) {
			if(min > p[i - k + 1 +j]) {
				min = p[i - k + 1 +j];
				index_min = i - k + 1 +j;
			}
		}
	}
	
	
	
	printf("%ld\n", count);
	
	return 0;
}