链接:https://codeforces.ml/problemset/problem/1185/C1
https://codeforces.ml/problemset/problem/1185/C2
题意:
最多花费T的时间来完成整场考试,现有n个人来参加,每个人都需要一定时间来考试;输出每个人最少需要干掉(bushi)前面几个人才能保证自己完成考试;(意会即可)
题解:
因为每个人考试花费的时间不超过100,就用数组存起来,如果轮到自己时间超标了就从100开始遍历到0,时间复杂度最多n*100;
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005] = { 0 };
int b[200005] = { 0 };
int c[105] = { 0 };
int main()
{
int n, t;
cin >> n >> t;
int sum = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
if (sum <= t)
{
b[i] = 0;
}
else
{
int x = sum;
int num = 0;
for (int j = 100; j >= 0; j--)
{
if (c[j] != 0)
{
if (x - j * c[j] <= t)
{
int cnt = c[j];
while (x - j * cnt <= t)
{
cnt--;
}
b[i] = cnt + num+1;
break;
}
else
{
x = x - j * c[j];
num += c[j];
}
}
}
}
c[a[i]]++;
}
for (int i = 0; i < n; i++)
{
cout << b[i] << " ";
}
cout << endl;
}