PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000181. Đếm đoạn có tổng không vượt quá K (Count Subarrays With Sum at Most 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ó tổng không vượt quá K (Count Subarrays With Sum at Most K)
Count Subarrays With Sum at Most K
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers and a nonnegative integer , count index pairs with and . Count only nonempty contiguous intervals, distinguishing intervals by their positions.
Input
The first line contains . The second contains integers .
Output
Print the number of valid intervals.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Example 1
Input
3 2
1 0 2
Output
5
Explanation
The valid intervals are [1,1], [2,2], [3,3], [1,2], [2,3]. The full interval sums to 3.
Example 2
Input
4 0
0 0 1 0
Output
4
Explanation
The first two zeros yield three intervals, and the last zero yields one.