PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000195. Đếm đoạn có điểm nhỏ hơn K (Count Subarrays With Score Less Than K)
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 đoạn có điểm nhỏ hơn K (Count Subarrays With Score Less Than K)
Count Subarrays With Score Less Than K
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers, define the score of a nonempty consecutive interval as . Count pairs whose score is strictly less than . Intervals at different positions are counted separately.
Input
The first line contains . The second contains exactly integers .
Output
Print the number of qualifying intervals.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
5 10
2 1 4 3 5
Output
6
Explanation
The five singletons and interval [1,2] (score 6) qualify. Interval [2,3] has score 10 and is excluded.
Example 2
Input
3 5
1 1 1
Output
5
Explanation
Three length-one and two length-two intervals qualify; the length-three interval scores 9.