PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000045. Đếm đoạn con có tổng trong khoảng (Count of Range Sum)
HỌC THEO LỘ TRÌNH
4 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn con có tổng trong khoảng (Count of Range Sum)
Count of Range Sum
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array and bounds , count contiguous subarrays whose sums lie in the inclusive interval . The answer is guaranteed to fit in a signed 32-bit integer.
Input
The first line contains . The second line contains integers .
Output
Print the number of subarrays whose sum lies in .
Subtasks
- Subtask 1 (20 points): ; ; ; đáp án vừa số nguyên 32-bit có dấu.
- Subtask 2 (30 points): ; ; ; đáp án vừa số nguyên 32-bit có dấu.
- Subtask 3 (50 points): ; ; ; đáp án vừa số nguyên 32-bit có dấu.
Examples
Input
3 -2 2
-2 5 -1
Output
3
Explanation
The three valid subarrays have sums -2, -1 and 2: , , and . Both endpoints are inclusive.