PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000166. Độ dài đoạn con có tổng không nhỏ hơn ngưỡng (Minimum Size Subarray Sum)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Độ dài đoạn con có tổng không nhỏ hơn ngưỡng (Minimum Size Subarray Sum)
Minimum Size Subarray Sum
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of positive integers and a positive target .
A contiguous subarray consists of positions through , where . Its sum is , and its length is .
Find the minimum length of a contiguous subarray whose sum is at least . If no such subarray exists, return .
Input
- The first line contains integers , the number of elements and the target sum.
- The second line contains exactly positive integers from left to right.
Output
Print one integer: the minimum length of a contiguous subarray with sum at least , or 0 if none exists.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
6 7
2 3 1 2 4 3
Output
2
Explanation
The array contains and the target is .
- Positions through give , with length .
- Positions through give , with length .
- Positions through give , with length .
No single element reaches because the maximum array value is . The subarray reaches the target with length , so the output is 2.