C2. Exam in BerSU (hard version)

 

 

https://codeforces.com/contest/1185/problem/C2

Meaning of the questions: n give you a number, from left to right order, ask for it each number, from left to right (that number) get some numbers, if the acquired digital sure to include this number, and these numbers accumulation can not exceed m, seeking for each number, it did not get a minimum of a few numbers falling.

Ideas: Each number range are subject to 1 to 100, this is a breakthrough, we can open an array to record the number of times each number appears, then for each number only need to sweep from left to right over this array, the smaller numbers took first, until I can not get up.

#include<bits/stdc++.h>
using namespace std;
int book[105];
int main()
{

    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        int t;
        scanf("%d",&t);
        int ans=0;
        int man=0;
        int sum=m-t;
        for(int j=1; j<=100; j++)
        {
            int flag=min(sum/j,book[j]);
            man+=flag;
            sum-=flag*j;
        }
        book[t]++;
        printf("%d ",i-1-man);
    }

}

 

Reproduced in: https: //www.cnblogs.com/dongdong25800/p/11063729.html

Guess you like

Origin blog.csdn.net/weixin_34259559/article/details/93691487