PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000088. Đếm chỉ số K-big (Count the Number of K-Big Indices)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm chỉ số K-big (Count the Number of K-Big Indices)
Count the Number of K-Big Indices
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array and a positive integer , positions are numbered from to .
An index is -big if both of the following conditions hold:
- There are at least indices with .
- There are at least indices with .
Different positions count separately, even if their values are equal. Only strictly smaller values qualify. Count all -big indices.
Input
The first line contains integers .
The second line contains exactly integers .
Output
Print one integer: the number of positions satisfying both -big conditions.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
6 2
2 3 6 5 2 3
Output
2
Explanation
For , consider the two qualifying positions:
- Position has value . There are two smaller values to its left and three to its right.
- Position has value . It has two smaller values on each side.
No other position has at least two strictly smaller values on both sides. The answer is 2.