原題傳送門spa
無
大家無恥的水題塏又回來了!!!(最近作題有點不順,刷刷水題找找自信)。
認真點,好吧,思路就是桶排,而後從大到小選擇奶牛(實際上運用了貪心的思想,易證(就是懶得證))。code
#include<cstdio> #include<queue> using namespace std; int t[10001]; int main() { int n,h,hi,i,ans=0; scanf("%d %d",&n,&h); for (i=0;i<n;i++) scanf("%d",&hi),t[hi]++; for (i=10000;h>0;i--) { if (i*t[i]<=h) h-=i*t[i],ans+=t[i]; else { ans+=h/i+1; break; } } printf("%d",ans); return 0; }