【Codeforces 1185C2】Exam in BerSU (hard version)

【链接】 我是链接,点我呀:)
【题意】


要让前i个数字的和小于等于M.
问你最少要删掉前i-1个数字中的多少个数字,每个询问都是独立的。

【题解】


ti的范围很小。
所以N*MAX(TI)暴力枚举就行。
如果超过了M的话显然是优先把大的数字删掉。

【代码】

#include <iostream>
using namespace std;

const int INF = 100;

int n,M;
int rest[INF+10];

int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> M;
    for (int i = 1;i <= n;i++){
        int x;
        cin >> x;
        rest[x]++;
        int temp = 0;
        for (int j = 1;j <= 100;j++) temp = temp + rest[j]*j;
        int ans = 0;
        if (temp>M){
            for (int j = 100;temp>M && j >= 1;j--){
                int need = (temp-M-1)/j + 1;
                need = min(need,rest[j]);
                if (j==x){
                    need = min(need,rest[j]-1);
                }
                ans+=need;
                temp = temp - j*need;
            }
        }
        cout<<ans<<' ';
    }
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/11139454.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值