codeforces 1185C2

题目:http://codeforces.com/problemset/problem/1185/C2

C2. Exam in BerSU (hard version)

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nn students. Students will take the exam one-by-one in order from 11-th to nn-th. Rules of the exam are following:

  • The ii-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 titi 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 MM minutes (maxti≤Mmaxti≤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 ii, you should count the minimum possible number of students who need to fail the exam so the ii-th student has enough time to pass the exam.

For each student ii, find the answer independently. That is, if when finding the answer for the student i1i1 some student jj should leave, then while finding the answer for i2i2 (i2>i1i2>i1) the student jj student does not have to go home.

Input

The first line of the input contains two integers nn and MM (1≤n≤2⋅1051≤n≤2⋅105, 1≤M≤2⋅1071≤M≤2⋅107) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains nn integers titi (1≤ti≤1001≤ti≤100) — time in minutes that ii-th student spends to answer to a ticket.

It's guaranteed that all values of titi are not greater than MM.

Output

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

Examples

input

Copy

7 15
1 2 3 4 5 6 7

output

Copy

0 0 0 0 0 2 3 

input

Copy

5 100
80 40 40 40 60

output

Copy

0 1 1 2 3 

Note

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed M=15M=15 (the sum is 1+2+3+4+5=151+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 00.

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

In order for the 77-th student to pass the exam, it is necessary that at least 33 students must fail it before (for example, the 22-nd, 55-th and 66-th, then the 77-th will finish its exam in 1+3+4+7=151+3+4+7=15 minutes, which does not exceed MM).

题目大意:有n个学生去考试,考试有m分钟,每个学生随机选择一个题依次进行考试,做出这个题消耗的时间为ti分钟,可以选择不做这个题,直接挂科消耗0分钟,问到第i个同学时,前面最少需要有多少个同学挂科,第i个同学可以完成考试。

题目解析:对于每个输入,做和sum,当sum<=m,直接输出0,否则依次消耗时间较长的学生,因为学生较大,但是题目消耗的时间只有100,所以对于每种难度的题储存他出现的次数,然后从大到小减就行了。

#include<iostream>
#include<queue>
#include<cstring> 
#include<cmath>
#include<map>
#include<algorithm>
#define up(i,x,y) for(i=x;i<=y;i++)  
#define down(i,x,y) for(i=x;i>=y;i--)  
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c))
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const int MAXN = 2750131;
ll T,n,m,i,j;
ll gcd(ll p,ll q)
{return q==0?p:gcd(q,p%q);}
 
int main()
{
	cin>>n>>m;
	ll sum=0,k,max=100;;
	ll a[105];
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++){
		cin>>k;
		sum+=k;
		if(sum<=m){
			cout<<"0 ";
		}
		else{
			ll sumb=sum;
			ll ans=0;
			for(j=max;j>=1;j--){
				if(a[j]==0){
					continue;
				}
				ll s=a[j]*j;
				sumb-=s;
				ans+=a[j];
				if(sumb<=m){
					ll ks=m-sumb;
					ans-=ks/j;
					break;
				}
			}
			cout<<ans<<" ";
		}
		a[k]++;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值