题解
2023-09-01 12:32:08
发布于:广东
3阅读
0回复
0点赞
复杂度:O(Nlog2N)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
int ar[n];
for (int i = 0; i < n; i++) { cin >> ar[i]; }
int hi = n, lo = 1;
int sol = n;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
int time = 0, j = 0;
priority_queue<int> pq;
int size = 0;
while (size < mid && j < n) {
pq.push(-ar[j]);
size++;
j++;
}
while ((int)pq.size()) {
time += max(0, -pq.top() - time);
pq.pop();
if (j < n) {
pq.push(-(ar[j] + time));
j++;
}
}
if (time > t) {
lo = mid + 1;
} else {
sol = min(sol, mid);
hi = mid - 1;
}
}
cout << sol << '\n';
}
这里空空如也
有帮助,赞一个