最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

CF 1767B - Block Towers

2023-07-05 10:04 作者:您是打尖兒還是住店呢  | 我要投稿

There are n block towers, numbered from 1 to n. The i-th tower consists of ai blocks.

In one move, you can move one block from tower i to tower j, but only if ai>aj. That move increases aj by 1 and decreases ai by 1. You can perform as many moves as you would like (possibly, zero).

What's the largest amount of blocks you can have on the tower 1 after the moves?

Input

The first line contains a single integer t (1≤t≤104) — the number of testcases.

The first line of each testcase contains a single integer n (2≤n≤2?105) — the number of towers.

The second line contains n integers a1,a2,…,an (1≤ai≤109) — the number of blocks on each tower.


The sum of n over all testcases doesn't exceed 2?105.


Output

For each testcase, print the largest amount of blocks you can have on the tower 1 after you make any number of moves (possibly, zero).

-------------------------------------------------------------

有n座塔樓,編號(hào)從1到n。 第 i 座塔由 ai 塊組成。

一次移動(dòng),您可以將一個(gè)方塊從 i 塔移動(dòng)到 j 塔,但前提是 ai>aj。 該移動(dòng)使 aj 增加 1,并將 ai 減少 1。您可以執(zhí)行任意數(shù)量的移動(dòng)(可能是零)。

移動(dòng)后 1 號(hào)塔上最多可以擁有多少塊方塊?

輸入

第一行包含一個(gè)整數(shù) t (1≤t≤104) — 測(cè)試用例的數(shù)量。

每個(gè)測(cè)試用例的第一行包含一個(gè)整數(shù) n (2≤n≤2?105) — 塔的數(shù)量。

第二行包含 n 個(gè)整數(shù) a1,a2,…,an (1≤ai≤109) — 每個(gè)塔上的塊數(shù)。


所有測(cè)試用例的 n 總和不超過 2?105。


輸出

對(duì)于每個(gè)測(cè)試用例,在進(jìn)行任意次數(shù)的移動(dòng)(可能為零)后,打印塔 1 上可以擁有的最大塊數(shù)。

----------------------------

只要先找跟a1最接近的值,然后把a(bǔ)1增加后,在繼續(xù)找,所以這里面可以用排序解決,但是我用數(shù)組排序,提交后,超時(shí)了。。。沒辦法就只能有優(yōu)先隊(duì)列了。還好通過了。。

下面是代碼:


CF 1767B - Block Towers的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
五家渠市| 晋中市| 鸡东县| 福泉市| 高要市| 吉安市| 桑植县| 屏东市| 连城县| 临猗县| 高邮市| 驻马店市| 安泽县| 河北区| 乌拉特中旗| 昆明市| 保山市| 施秉县| 彰化市| 阜南县| 淮阳县| 蓝山县| 湖南省| 甘南县| 宣化县| 天峻县| 安化县| 莫力| 石泉县| 广州市| 苍南县| 阿拉尔市| 新泰市| 大兴区| 旬阳县| 江陵县| 凤庆县| 金华市| 宣恩县| 和平区| 高平市|