PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000122. Đếm cách chia mảng hợp lệ (Number of Ways to Split Array)
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 cách chia mảng hợp lệ (Number of Ways to Split Array)
Number of Ways to Split Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An integer array may contain negative values. Choose with to split it into the nonempty parts with indices and . A split is valid when the left sum is at least the right sum. Count valid indices.
Input
The first line contains . The second line contains integers .
Output
Print the number of valid splits.
Subtasks
- Subtask 1 (20 points): ; for .
- Subtask 2 (30 points): ; for .
- Subtask 3 (50 points): ; for .
Example 1
Input
4
10 4 -8 7
Output
2
Explanation
The three splits give sum pairs (10,3), (14,-1), (6,7). The first two qualify; the last does not.
Example 2
Input
4
2 3 1 0
Output
2
Explanation
The sum pairs are (2,4), (5,1), (6,0). Only the last two qualify.