#include <iostream> #include <math.h> #include <stdio.h> #include<algorithm> #include<cstring> #include<queue> using namespace std; int data[100005]; int main() { int T,n,t; scanf("%d",&T); while(T--) { int tmp; scanf("%d%d",&n,&t); for(int i=0;i<n;i++) { scanf("%d",&data[i]); } sort(data,data+n); int l=2,r=n; while(l<r) { int mid=(l+r)/2; int i = 0; while (data[i]==0 && i<n) i++; long long ansT = 0, pos = 0; queue<int> que; i--; if(i==-1) i=0; int tmp = (n-i-1)%(mid-1); if (tmp) { tmp++; while (tmp--) pos += data[i++]; que.push(pos); ansT += pos; } while (i<n||que.size() > 1) { pos = 0; for (int j = 0; j < mid; j++) { if (i == n && que.empty()) break; if (que.empty()) { pos += data[i++]; continue; } else if (i == n) { pos += que.front(); que.pop(); continue; } else if (data[i] < que.front()) { pos += data[i++]; } else { pos += que.front(); que.pop(); } } ansT += pos; que.push(pos); } if(ansT<=t) r=mid; else l=mid+1; } printf("%d\n",l); //printf("%d\n",r); } return 0; } /* 100 3 3 1 2 4 1 2 2 3 3 1 */
时间: 2024-10-13 07:24:32