题解
假如最后有 \(k\) 个月购买过幸福,那么这 \(k\) 个月的价格一定是前 \(k\) 小的
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
int m,x;
cin>>m>>x;
priority_queue<int> q;
ll left=0;
for(int i=1;i<=m;i++)
{
int c;
cin>>c;
left-=c;
q.push(c);
while(left<0)
{
left+=q.top();
q.pop();
}
}
cout<<q.size()<<"\n";
}
return 0;
}
标签:Less,int,Money,ll,cin,long,Buys,Now,left
From: https://www.cnblogs.com/pure4knowledge/p/18206578