# 題目
AP325 Q-4-18. 少林寺的櫃姐
# 解題思路
目前沒東西...
# 程式碼
#include<bits/stdc++.h> | |
using namespace std; | |
#define N 100005 | |
int t[N],n,D; | |
bool enough(int m){ | |
priority_queue<int> pq; | |
int mx=0; | |
for(int i=0,buffer;i<n;i++){ | |
buffer=t[i]; | |
if((int)pq.size()<m) | |
pq.push(-buffer); | |
else{ | |
buffer+=-(pq.top()); | |
pq.pop(); | |
pq.push(-buffer); | |
} | |
mx=max(mx,buffer); | |
} | |
if(mx>D) return false; | |
else return true; | |
} | |
int main(){ | |
cin>>n>>D; | |
for(int i=0;i<n;i++) | |
cin>>t[i]; | |
int tower=0; | |
for(int jump=n/2;jump>0;jump>>=1){ | |
while(tower+jump<n && !enough(jump+tower)) | |
tower+=jump; | |
} | |
cout<<++tower; | |
return 0; | |
} |