题解
一句话总结:第 \(i\) 头奶牛继承场上 \(k\) 头奶牛里结束时间最短的
code
#include<bits/stdc++.h>
using namespace std;
int n,t;
int d[100005];
int check(int k)
{
priority_queue<int,vector<int> ,greater<int> > q;
for(int i=1;i<=n;i++)
{
if(q.size()<k) q.push(d[i]);
else
{
q.push(d[i]+q.top());
q.pop();
}
}
while(q.size()>1) q.pop();
return q.top()<=t;
}
int main()
{
cin>>n>>t;
for(int i=1;i<=n;i++) cin>>d[i];
int l=0,r=1e4;
while(l+1<r)
{
int mid=(l+r)/2;
if(check(mid)) r=mid;
else l=mid;
}
cout<<r<<endl;
return 0;
}
标签:USACO17JAN,Cow,Show,int,P3611,Dance
From: https://www.cnblogs.com/pure4knowledge/p/18201684