#FT0000134. Kỳ thi BerSU – Bản khó (Exam in BerSU)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Kỳ thi BerSU – Bản khó (Exam in BerSU)
Exam in BerSU — Hard Version
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are students taking an exam in the fixed order . Student , if allowed to take the exam, requires exactly minutes; a student who leaves takes no time. The entire examination period lasts minutes.
For each student , student must be able to finish the exam. You may make some of the preceding students leave so that the sum of the remaining preceding students' exam times plus does not exceed .
Determine the minimum number of preceding students who must leave. Each student is considered independently; a choice made for one query does not affect subsequent queries.
The current student may not be removed. The input guarantees , so a feasible choice always exists.
Input
The first line contains . The second line contains integers , the required exam times.
Output
Print integers on one line; the -th number is the minimum number of preceding students to exclude.
Subtasks
- Subtask 1 (20 points): ; ; and for every .
- Subtask 2 (30 points): ; ; and for every .
- Subtask 3 (50 points): ; ; and for every .
Examples
Example 1
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Explanation
For students through , all preceding students and the current student fit within minutes, so the answers are zero. For student , the total is ; excluding the preceding times and leaves , and one exclusion is insufficient. For student , the total is ; removing preceding times saves minutes and leaves . Two exclusions cannot save enough time.
Example 2
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Explanation
Student 2 requires minutes, so the preceding -minute student must leave: the answer is . For student 4, the three preceding students total ; including their own gives , requiring at least two exclusions (one and one ). For student 5, the total would be ; excluding leaves , so three exclusions suffice and two cannot.