PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000163. Đếm đoạn con có tổng đủ lớn (Enough Array)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn con có tổng đủ lớn (Enough Array)
Enough Array
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers and a positive integer . A contiguous subarray consists of with . Count pairs whose subarray sum is at least . Different index pairs count separately, even when their values form identical sequences.
Input
- The first line contains and .
- The second line contains positive integers .
Output
Print the number of contiguous subarrays with sum at least .
Subtasks
- Subtask 1 (20 points): ; ; for all .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; ; for all .
Examples
Input
4 10
6 1 2 7
Output
2
Explanation
For and , sums of subarrays starting at 1 are , so only qualifies. Starting at 2 gives , so only qualifies. No subarray starting at 3 or 4 qualifies. Exactly two subarrays are counted; print 2.