cf Dolce Vita(C)

Turbulent times are coming, so you decided to buy sugar in advance. There are nn shops around that sell sugar: the ii-th shop sells one pack of sugar for aiai 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 aiai, during the second day cost is ai+1ai+1, during the third day — ai+2ai+2 and so on for each shop ii.

On the contrary, your everyday budget is only xx coins. In other words, each day you go and buy as many packs as possible with total cost not exceeding xx. 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 xx, 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 tt (1≤t≤10001≤t≤1000) — the number of test cases. Next tt cases follow.

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

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the initial cost of one pack in each shop.

It's guaranteed that the total sum of nn doesn't exceed 2⋅1052⋅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][2,1,2]. You can buy all 33 packs, since 2+1+2≤72+1+2≤7.
  • Day 2: prices are [3,2,3][3,2,3]. You can't buy all 33 packs, since 3+2+3>73+2+3>7, so you buy only 22 packs.
  • Day 3: prices are [4,3,4][4,3,4]. You can buy 22 packs with prices 44 and 33.
  • Day 4: prices are [5,4,5][5,4,5]. You can't buy 22 packs anymore, so you buy only 11 pack.
  • Day 5: prices are [6,5,6][6,5,6]. You can buy 11 pack.
  • Day 6: prices are [7,6,7][7,6,7]. You can buy 11 pack.
  • Day 7: prices are [8,7,8][8,7,8]. You still can buy 11 pack of cost 77.
  • Day 8: prices are [9,8,9][9,8,9]. Prices are too high, so you can't buy anything.

In total, you bought 3+2+2+1+1+1+1=113+2+2+1+1+1+1=11 packs.

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.

In the fourth test case, you can buy 22 packs first 500500 days. At day 501501 prices are [501,501][501,501], so you can buy only 11 pack the next 500500 days. At day 10011001 prices are [1001,1001][1001,1001] so can't buy anymore. In total, you bought 500⋅2+500⋅1=1500500⋅2+500⋅1=1500 packs.

心情:以前傻傻的,总会觉得人是最重要的,到后来发现自己是真的错了,其实她什么都不是,没有什么比取悦自己,提升自己更重要,如果我连自己的希望都照顾不好,那我也太对不起自己了,以后永远不要拿人与学习做对比,学习的地位永远是最重要的,来的人一定是过客,如果不是过客,那我想我也不会是现在的B样,不要拿自己一瓶不满半瓶晃荡的技术去显摆,自己离优秀还有很远,不会再让别人来打扰我原来平静的生活,我继续完成我未完成的,为什么要作贱自己去管别人呢

思路:这个题是问在每次增加1的情况下,每次最多能买多少包糖。一般是横向观察,就是看第一天买那几个,第二天买哪几个……

竖式计算(竖式相加):现在我们要竖着看,竖着看每包最多能买到第几天,算出每包的天数,将它们的总和加起来即可。

 最便宜的能买的天数最多,在选中最便宜的情况下,再去选其他的,这样才能选最多。我们可以去模拟天数增加,选中一包的时候每天能买的增速是1,选中两包的时候每天能买的增速是2,以此类推,增速是和每天购买的包数相同的。所以我们枚举包数,然后用除法去计算在买 i 包的情况下能买几天,然后将每包的天数相加即可。

完整代码:

#include <bits/stdc++.h>

using namespace std;

#define int long long
const int mod=1e9+7;

const int N=2e5+10;
int a[N];

void solve()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }

    sort(a+1,a+1+n);
    int res=0;
    for(int i=1;i<=n;i++)
    {
        m-=a[i];
        if(m<0)break;
        res+=m/i+1;
    }
    cout<<res<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值