五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

CF 1746B - Rebellion

2023-08-19 11:49 作者:您是打尖兒還是住店呢  | 我要投稿

You have an array a of size n consisting only of zeroes and ones. You can do the following operation:

choose two indices 1≤i,j≤n, i≠j,add ai to aj,remove ai from a.

Note that elements of a can become bigger than 1 after performing some operations. Also note that n becomes 1 less after the operation.

What is the minimum number of operations needed to make a non-decreasing, i. e. that each element is not less than the previous element?


Input

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

The first line of each test case contains an integer n (1≤n≤105), the size of array a.

Next line contains n integers a1,a2,…an (ai is 0 or 1), elements of array a.


It's guaranteed that sum of n over all test cases doesn't exceed 2?105.


Output

For each test case print a single integer, minimum number of operations needed to make a non-decreasing.

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

您有一個(gè)大小為 n 的數(shù)組 a,僅由 0 和 1 組成。 您可以進(jìn)行以下操作:

選擇兩個(gè)索引1≤i,j≤n,i≠j,將ai添加到aj,從a中刪除ai。

請(qǐng)注意,執(zhí)行某些操作后,a 的元素可能會(huì)變得大于 1。 另請(qǐng)注意,運(yùn)算后 n 會(huì)減 1。

進(jìn)行非遞減運(yùn)算所需的最少操作次數(shù)是多少,即? e. 每個(gè)元素不小于前一個(gè)元素?


輸入

每個(gè)測(cè)試包含多個(gè)測(cè)試用例。 第一行包含測(cè)試用例的數(shù)量 t (1≤t≤104)。 測(cè)試用例的描述如下。

每個(gè)測(cè)試用例的第一行包含一個(gè)整數(shù)n(1≤n≤105),即數(shù)組a的大小。

下一行包含 n 個(gè)整數(shù) a1,a2,…an(ai 為 0 或 1),數(shù)組 a 的元素。


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


輸出

對(duì)于每個(gè)測(cè)試用例打印一個(gè)整數(shù),實(shí)現(xiàn)非遞減所需的最小操作數(shù)。

-----------------------雙指針處理;

下面是代碼:


CF 1746B - Rebellion的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
正镶白旗| 龙胜| 济阳县| 治县。| 龙胜| 兴安盟| 寿光市| 任丘市| 嫩江县| 老河口市| 育儿| 修文县| 成武县| 仙居县| 惠安县| 扶沟县| 瓦房店市| 涪陵区| 厦门市| 临泉县| 铅山县| 南靖县| 佳木斯市| 二连浩特市| 游戏| 临城县| 县级市| 安义县| 定陶县| 治县。| 永福县| 定州市| 曲阜市| 尉犁县| 浦江县| 定兴县| 阜南县| 龙江县| 华池县| 顺平县| 南城县|