PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000205. Tổng dương nhỏ nhất (Minimum Positive Subarray Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng dương nhỏ nhất (Minimum Positive Subarray Sum)
Minimum Positive Subarray Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , find the smallest strictly positive sum of a nonempty consecutive interval. Print -1 if no such interval exists.
Input
The first line contains . The second line contains exactly integers .
Output
Print the minimum positive sum, or -1 if none exists.
Subtasks
- Subtask 1 (25 points): ; .
- Subtask 2 (25 points): ; ; .
- Subtask 3 (50 points): ; .
Example 1
Input
3
3 -2 1
Output
1
Explanation
Intervals [1,2] and [3,3] sum to 1, the smallest possible positive integer.
Example 2
Input
3
-2 0 -3
Output
-1
Explanation
Every interval has a nonpositive sum.