C. Dolce Vita-Educational Codeforces Round 127 (Rated for Div. 2)

Problem - 1671C - Codeforces

C. 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 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.

比较有意思的题,首先肯定是能尽可能的买便宜的,所以可以先排个序,计算前缀和。后序遍历前缀和,每一次我们计算当前前缀和及其附加值(天数)与x的大小关系,大于直接continue,否则我们及计算本位置所能继续的天数,计算方法为x-前缀和-附加值的结果整除当前天数i,获得的结果再+1

# include<iostream>
# include<vector>
# include<cstring>
# include<map>
# include<algorithm>
# define mod 1000000007
using namespace std;
typedef long long int ll;

ll sum[200000+10],a[200000+10];

int main ()
{

 /*

 倒序遍历前缀和,当前前缀和若大于x,
 则向前推移至小于等于的位置
 在小于等于的位置,计算差值,若差a,则a整除当前数目,得出能增加的天数
 也就是下一个位置每个商店都增加的天数

 */

 int t;

 cin>>t;

 while(t--)
 {
     ll temp=0;


     ll n,m;

     cin>>n>>m;

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


     }

     sort(a+1,a+1+n);

     for(int i=1;i<=n;i++)
     {
         sum[i]=sum[i-1]+a[i];

     }

     ll ans=0;

     for(int i=n;i>=1;i--)
     {
         if(m>=sum[i]+temp*i)
         {
             ll cha=m-(sum[i]+temp*i);

             cha/=i;

             cha++;

             ans+=cha*i;

             temp+=cha;

         }

     }

     cout<<ans<<endl;

 }




    return 0;

}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值