Dolce Vita

Dolce Vita
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Turbulent times are coming, so you decided to buy sugar in advance. There are n shops around that sell sugar: the i-th shop sells one pack of sugar for ai coins, but only one pack to one customer each day. So in order to buy several packs, you need to visit several shops.

Another problem is that prices are increasing each day: during the first day the cost is ai, during the second day cost is ai+1+1, during the third day — ai+2+2 and so on for each shop i.

On the contrary, your everyday budget is only x coins. In other words, each day you go and buy as many packs as possible with total cost not exceeding x. Note that if you don't spend some amount of coins during a day, you can't use these coins during the next days.

Eventually, the cost for each pack will exceed x, and you won't be able to buy even a single pack. So, how many packs will you be able to buy till that moment in total?

Input

The first line contains a single integer t (1t10001≤≤1000) — the number of test cases. Next t cases follow.

The first line of each test case contains two integers n and x (1n21051≤≤2⋅105; 1x1091≤≤109) — the number of shops and your everyday budget.

The second line of each test case contains n integers a1,a2,,an1,2,…, (1ai1091≤≤109) — the initial cost of one pack in each shop.

It's guaranteed that the total sum of n doesn't exceed 21052⋅105.

Output

For each test case, print one integer — the total number of packs you will be able to buy until prices exceed your everyday budget.

Example
input Copy
4
3 7
2 1 2
5 9
10 20 30 40 50
1 1
1
2 1000
1 1
output Copy
11 0 1 1500
Note

In the first test case,

  • Day 1: prices are [2,1,2] You can buy all 33 packs, since 2+1+27
  • Day 2: prices are [3,2,3You can't buy all 33 packs, since 3+2+3>7, so you buy only 22 packs.
  • Day 3: prices are [4,3,4] You can buy 22 packs with prices 4 and 3.
  • Day 4: prices are [5,4,5] You can't buy 22 packs anymore, so you buy only 1 pack.
  • Day 5: prices are [6,5,6] You can buy 1 pack.
  • Day 6: prices are [7,6,7] You can buy 1 pack.
  • Day 7: prices are [8,7,8] You still can buy 11 pack of cost 77.
  • Day 8: prices are [9,8,9]. Prices are too high, so you can't buy anything.
In total, you bought 3+2+2+1+1+1+1=11packs.

In the second test case, prices are too high even at the first day, so you can't buy anything.

In the third test case, you can buy only one pack at day one.

//本质是贪心,每天所有的价值都+1,一开始想的是差分和前缀和,但是差分好像不太行,因为是整体区间 //考虑贪心,每天都要+1,利用前缀和,从后向前枚举,找到最多可以买的糖果数,利用ans作为天数维护前缀和 //有以下性质: s+day*i<=num才可以,然后从这个数目出发,看看这个数目能撑几天 //有以下方程: 能撑的天数=num-s[i]-++day*i,然后计入总数 糖果数=(能撑的天数+最开始的天数)*现在的糖果数 //最后更新天数,现在得天数=1+当前糖果数能撑的天数 #include <bits/stdc++.h> //#define int long long using namespace std; const int N=1e5+10,mod=1e9+7; long long n,t,a[N],f[N],res,num,ans,s[N]; bool vis[N]; int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>num; res=0,ans=0; for(int i=1;i<=n;i++) cin>>s[i]; sort(s+1,s+1+n); for(int i=1;i<=n;i++) s[i]+=s[i-1];//前缀和 for(int i=n;i>=1;i--){ if(s[i]+ans*i>num) continue; //利用ans来维护前缀和 long long cnt=((num-s[i]-ans*i)/i)+1; res+=cnt*i; ans+=cnt; } cout<<res<<endl; } return 0; }

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17513358.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
-- --
点击右上角即可分享
微信分享提示