PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000134. Kỳ thi BerSU – Bản khó (Exam in BerSU)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn students taking an exam in the fixed order 1,2,…,n1,2,\ldots,n. Student jj, if allowed to take the exam, requires exactly tjt_j minutes; a student who leaves takes no time. The entire examination period lasts MM minutes.

For each student ii, student ii must be able to finish the exam. You may make some of the preceding students 1,…,i−11,\ldots,i-1 leave so that the sum of the remaining preceding students' exam times plus tit_i does not exceed MM.

Determine the minimum number of preceding students who must leave. Each student ii is considered independently; a choice made for one query does not affect subsequent queries.

The current student ii may not be removed. The input guarantees ti≤Mt_i\le M, so a feasible choice always exists.

Input

The first line contains n,Mn,M. The second line contains nn integers t1,…,tnt_1,\ldots,t_n, the required exam times.

Output

Print nn integers on one line; the ii-th number is the minimum number of preceding students to exclude.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 1≤M≤200000001\le M\le 20000000; 1≤ti≤1001\le t_i\le 100 and ti≤Mt_i\le M for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 1≤M≤200000001\le M\le 20000000; 1≤ti≤1001\le t_i\le 100 and ti≤Mt_i\le M for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤M≤200000001\le M\le 20000000; 1≤ti≤1001\le t_i\le 100 and ti≤Mt_i\le M for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

7 15
1 2 3 4 5 6 7

Output

0 0 0 0 0 2 3

Explanation

For students 11 through 55, all preceding students and the current student fit within 1515 minutes, so the answers are zero. For student 66, the total is 2121; excluding the preceding times 33 and 44 leaves 14≤1514\le15, and one exclusion is insufficient. For student 77, the total is 2828; removing preceding times 6,5,26,5,2 saves 1313 minutes and leaves 1515. 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 4040 minutes, so the preceding 8080-minute student must leave: the answer is 11. For student 4, the three preceding students total 160160; including their own 4040 gives 200200, requiring at least two exclusions (one 8080 and one 4040). For student 5, the total would be 260260; excluding 80+40+40=16080+40+40=160 leaves 100100, so three exclusions suffice and two cannot.