B. [Binary Search] Altetris time limit per test: 2 seconds…

Written by Anonymous on June 15, 2026 in Uncategorized with no comments.

Questions

B. [Binаry Seаrch] Altetris time limit per test: 2 secоnds memоry limit per test: 256 megаbytes Altetris is a variatiоn of Tetris played on a grid with n columns. Initially, the i-th column contains ai blocks stacked from the bottom upward. In addition, blocks cannot float: every block must either rest on the bottom of the grid or on top of another block. You are then given m independent 1x1 blocks, which may be placed in any columns. Determine the maximum number of completely filled rows that can exist after placing all m blocks optimally. The figure bellow illustrates one example of this problem, with the area highlighted in green indicating where the independent 1x1 blocks would be placed. Input The first line contains a single integer t (1≤t≤104) — the number of test cases. The first line of each test case contains two positive integers n and m (1≤n≤2⋅105; 1≤m≤109) — the number of columns of the grid and the number of independent 1x1 blocks available. The second line of each test case contains n space-separated integers ai (1≤ai≤109) — the number of blocks per column. The sum of n over all test cases doesn't exceed 2⋅105. Output For each test case, output a single positive integer r (r≥1) — the number of completely filled rows after adding independent blocks optimally. Examples Input Output 57 93 1 2 4 6 2 54 13 4 1 41 100000000013 101 1 16 19841 2 5 6 8 9 4210000000014335  

Comments are closed.