#PS0000123. Các vị trí chia có điểm lớn nhất (All Divisions With the Highest Score of a Binary Array)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các vị trí chia có điểm lớn nhất (All Divisions With the Highest Score of a Binary Array)
All Divisions With the Highest Score of a Binary Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a binary array , choose a division index between 0 and , inclusive. The left part contains the first entries and the right part contains the last entries. Either part may be empty at an endpoint. The score counts zeros on the left and ones on the right. Find every division index attaining the maximum score.
Input
The first line contains . The second line contains integers .
Output
Print one line containing all maximizing division indices separated by spaces. Each index must appear once; any order is accepted.
Subtasks
- Subtask 1 (20 points): ; for .
- Subtask 2 (30 points): ; for ; .
- Subtask 3 (50 points): ; for .
Example 1
Input
4
0 0 1 0
Output
2 4
Explanation
Scores at indices 0 through 4 are 1,2,3,2,3. The maximum 3 occurs at 2 and 4; 4 2 is also accepted.
Example 2
Input
3
0 0 0
Output
3
Explanation
Scores are 0,1,2,3. Only index 3 maximizes the score.
Example 3
Input
2
1 1
Output
0
Explanation
Scores are 2,1,0; only 0 is optimal.