Codeforces Round 568 (Div. 2)
C2
Exam in BerSU (hard version)
Codeforces
1700
原题
← C1D →
翻译中…

The only difference between easy and hard versions is constraints.

翻译中…

If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.

翻译中…

A session has begun at Beland State University. Many students are taking exams.

翻译中…

Polygraph Poligrafovich is going to examine a group of $n$ students. Students will take the exam one-by-one in order from $1$-th to $n$-th. Rules of the exam are following:

翻译中…
  • The $i$-th student randomly chooses a ticket.
  • if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
  • if the student finds the ticket easy, he spends exactly $t_i$ minutes to pass the exam. After it, he immediately gets a mark and goes home.
翻译中…

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

翻译中…

The duration of the whole exam for all students is $M$ minutes ($\max t_i \le M$), so students at the end of the list have a greater possibility to run out of time to pass the exam.

翻译中…

For each student $i$, you should count the minimum possible number of students who need to fail the exam so the $i$-th student has enough time to pass the exam.

翻译中…

For each student $i$, find the answer independently. That is, if when finding the answer for the student $i_1$ some student $j$ should leave, then while finding the answer for $i_2$ ($i_2 \gt i_1$) the student $j$ student does not have to go home.

翻译中…

Input

翻译中…

The first line of the input contains two integers $n$ and $M$ ($1 \le n \le 2 \cdot 10^5$, $1 \le M \le 2 \cdot 10^7$) — the number of students and the total duration of the exam in minutes, respectively.

翻译中…

The second line of the input contains $n$ integers $t_i$ ($1 \le t_i \le 100$) — time in minutes that $i$-th student spends to answer to a ticket.

翻译中…

It's guaranteed that all values of $t_i$ are not greater than $M$.

翻译中…

Output

翻译中…

Print $n$ numbers: the $i$-th number must be equal to the minimum number of students who have to leave the exam in order to $i$-th student has enough time to pass the exam.

翻译中…

Note

翻译中…

The explanation for the example 1.

翻译中…

Please note that the sum of the first five exam times does not exceed $M=15$ (the sum is $1+2+3+4+5=15$). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are $0$.

翻译中…

In order for the $6$-th student to pass the exam, it is necessary that at least $2$ students must fail it before (for example, the $3$-rd and $4$-th, then the $6$-th will finish its exam in $1+2+5+6=14$ minutes, which does not exceed $M$).

翻译中…

In order for the $7$-th student to pass the exam, it is necessary that at least $3$ students must fail it before (for example, the $2$-nd, $5$-th and $6$-th, then the $7$-th will finish its exam in $1+3+4+7=15$ minutes, which does not exceed $M$).

翻译中…

样例

Input #1
7 15
1 2 3 4 5 6 7
Output #1
0 0 0 0 0 2 3
InputCopy OutputCopy
Input #2
5 100
80 40 40 40 60
Output #2
0 1 1 2 3
InputCopy OutputCopy
题目信息
题号
1185C2
时间限制
2 s
内存限制
256 MB
标签
暴力
数据结构
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。