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

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
屯门区| 清水县| 张家川| 大悟县| 宣城市| 金门县| 张家界市| 阿克苏市| 郓城县| 安国市| 大渡口区| 手机| 大石桥市| 盐边县| 高陵县| 商洛市| 巴楚县| 墨竹工卡县| 昭苏县| 秀山| 海宁市| 翁源县| 三台县| 新沂市| 琼海市| 余庆县| 哈巴河县| 天门市| 雷山县| 林西县| 揭西县| 古丈县| 库车县| 宁南县| 洛扎县| 始兴县| 桐柏县| 达日县| 文昌市| 青龙| 多伦县|