Codeforces Round 975 (Div. 2) C. Cards Partition

C. Cards Partition

time limit per test: 2 seconds

memory limit per test: 256 megabytes

DJ Genki vs Gram - Einherjar Joker


You have some cards. An integer between 1 and n is written on each card: specifically, for each i from 1 to n, you have ai cards which have the number i written on them.

There is also a shop which contains unlimited cards of each type. You have k coins, so you can buy at most k new cards in total, and the cards you buy can contain any integer between 1 and n, inclusive.

After buying the new cards, you must partition all your cards into decks, according to the following rules:

  • all the decks must have the same size;
  • there are no pairs of cards with the same value in the same deck.

Find the maximum possible size of a deck after buying cards and partitioning them optimally.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10^4). The description of the test cases follows.

The first line of each test case contains two integers n, k (1≤n≤2⋅10^5, 0≤k≤10^16) --- the number of distinct types of cards and the number of coins.

The second line of each test case contains n integers a1,a2,...,an (0≤ai≤10^10, ∑ai≥1) --- the number of cards of type i you have at the beginning, for each 1≤i≤n.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅10^5.

Output

For each test case, output a single integer: the maximum possible size of a deck if you operate optimally.

Example

Input

9

3 1

3 2 2

5 4

2 6 1 2 4

2 100

1410065408 10000000000

10 8

7 4 6 6 9 3 10 2 8 7

2 12

2 2

2 70

0 1

1 0

1

3 0

2 1 2

3 1

0 3 3

Output

2

3

1

7

2

2

1

1

2

Note

In the first test case, you can buy one card with the number 1, and your cards become 1,1,1,1,2,2,3,3. You can partition them into the decks 1,2,1,2,1,3,1,3: they all have size 2, and they all contain distinct values. You can show that you cannot get a partition with decks of size greater than 2, so the answer is 2.

In the second test case, you can buy two cards with the number 1 and one card with the number 3, and your cards become 1,1,1,1,2,2,2,2,2,2,3,3,4,4,5,5,5,5, which can be partitioned into 1,2,3,1,2,4,1,2,5,1,2,5,2,3,5,2,4,5. You can show that you cannot get a partition with decks of size greater than 3, so the answer is 3.

【思路分析】

思维。显然划分后每组牌数(即size)不超过n,那么要求size最大,只需要从n到1枚举size即可。对每个size,计算出还需要购买的牌数,跟k作比较即可。

cpp 复制代码
#include<bits/stdc++.h>

#define i64 long long

using namespace std;

void solve() {
    i64 n, k;
    cin >> n >> k;
    i64 maxn = 0, sum = 0;
    i64 a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        maxn = max(maxn, a[i]);
        sum += a[i];
    }
    while (n >= 0) {
        i64 cnt = max(maxn, (sum + n - 1) / n);
        if (cnt * n - sum <= k) break;
        n--;
    }
    cout << n << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
相关推荐
Eric 辰东1 分钟前
【C 语言程序的编译和链接】详解编译链接过程
c语言·笔记·算法·学习方法
并不喜欢吃鱼1 分钟前
从零开始 C++-----十一【C++ 数据结构】红黑树全解析:从定义到工程实现(一文搞定,十分详细)
开发语言·数据结构·c++
星恒随风1 分钟前
C语言数据结构排序算法详解(上):从插入排序、希尔排序到选择排序、堆排序
c语言·数据结构·笔记·学习·排序算法
不会C语言的男孩2 分钟前
C++ Primer Plus 第7章:函数——C++的编程模块
开发语言·c++
方也_arkling3 分钟前
【Java-Day09】继承
java·开发语言
迈巴赫车主4 分钟前
蓝桥杯21247弹跳鞋java
java·开发语言·数据结构·算法·职场和发展·蓝桥杯
SoftLipaRZC10 分钟前
C语言数据在内存中的存储:整型与浮点型的秘密
c语言·开发语言
悟乙己11 分钟前
python DoWhy 库使用案例: SaaS 公司的客服案例
开发语言·python
社交怪人16 分钟前
【2的幂】信息学奥赛一本通C语言解法(题号1037)
c语言
就叫_这个吧17 分钟前
JavaScript基础数据类型、运算符、数组、函数的定义及DOM方式应用
开发语言·前端·javascript