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

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

CF 1778A - Flip Flop Sum

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

You are given an array of n integers a1,a2,…,an. The integers are either 1 or ?1. You have to perform the following operation exactly once on the array a:

Choose an index i (1≤i<n) and flip the signs of ai and ai+1. Here, flipping the sign means ?1 will be 1 and 1 will be ?1.

What is the maximum possible value of a1+a2+…+an after applying the above operation?

Input

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

The first line of each test case contains a single integer n (2≤n≤105), the length of the array a.


The next line contains n integers a1,a2,…,an (ai=1 or ai=?1).

The sum of n over all cases doesn't exceed 105.

Output

For each test case, print the maximum possible sum of the array a

?you can get in a separate line.

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

給定一個由 n 個整數(shù) a1,a2,…,an 組成的數(shù)組。 整數(shù)為 1 或 -1。 您必須對數(shù)組 a 執(zhí)行一次以下操作:

選擇一個索引 i (1≤i<n) 并翻轉(zhuǎn) ai 和 ai+1 的符號。 這里,翻轉(zhuǎn)符號意味著-1將是1,1將是-1。

應(yīng)用上述運算后,a1+a2+…+an 的最大可能值是多少?

輸入

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

每個測試用例的第一行包含一個整數(shù)n(2≤n≤105),即數(shù)組a的長度。


下一行包含 n 個整數(shù) a1,a2,…,an(ai=1 或 ai=?1)。

所有案例的 n 總和不超過 105。

輸出

對于每個測試用例,打印數(shù)組 a 的最大可能和

? 你可以單獨排隊。

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

看是否有連續(xù)的負(fù)數(shù),是否有負(fù)數(shù),這兩個信息,然后給出對應(yīng)的值即可;

easy題目:

下面是代碼:


CF 1778A - Flip Flop Sum的評論 (共 條)

分享到微博請遵守國家法律
徐州市| 霍林郭勒市| 金溪县| 晋城| 罗平县| 西昌市| 彩票| 时尚| 湘阴县| 渑池县| 且末县| 秭归县| 腾冲县| 胶州市| 蓝田县| 土默特右旗| 铅山县| 米脂县| 洱源县| 常山县| 石门县| 右玉县| 乌兰浩特市| 方城县| 岳西县| 同德县| 建平县| 秀山| 英超| 龙口市| 睢宁县| 潼关县| 吉安市| 应城市| 彰化市| 高密市| 洛扎县| 通化市| 四会市| 义乌市| 西昌市|