309306: CF1660D. Maximum Product Strikes Back
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:77
Solved:0
Description
Maximum Product Strikes Back
题意翻译
### 题目描述 你有一个长度为 $n$ 的数组,每一个元素都在 $-2$ 和 $2$ 之间,当从数组首删去 $x$ 个元素,从数组末删去 $y$ 个元素时,数组剩下的乘积最大,输出 $x$ 和 $y$ 。 特别地,当存在多种情况时,输出任意一种即可; 当数组为空时,这个数组的乘积被认为是 $1$ 。题目描述
You are given an array $ a $ consisting of $ n $ integers. For each $ i $ ( $ 1 \le i \le n $ ) the following inequality is true: $ -2 \le a_i \le 2 $ . You can remove any number (possibly $ 0 $ ) of elements from the beginning of the array and any number (possibly $ 0 $ ) of elements from the end of the array. You are allowed to delete the whole array. You need to answer the question: how many elements should be removed from the beginning of the array, and how many elements should be removed from the end of the array, so that the result will be an array whose product (multiplication) of elements is maximal. If there is more than one way to get an array with the maximum product of elements on it, you are allowed to output any of them. The product of elements of an empty array (array of length $ 0 $ ) should be assumed to be $ 1 $ .输入输出格式
输入格式
The first line of input data contains an integer $ t $ ( $ 1 \le t \le 10^4 $ ) —the number of test cases in the test. Then the descriptions of the input test cases follow. The first line of each test case description contains an integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) —the length of array $ a $ . The next line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ |a_i| \le 2 $ ) — elements of array $ a $ . It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
For each test case, output two non-negative numbers $ x $ and $ y $ ( $ 0 \le x + y \le n $ ) — such that the product (multiplication) of the array numbers, after removing $ x $ elements from the beginning and $ y $ elements from the end, is maximal. If there is more than one way to get the maximal product, it is allowed to output any of them. Consider the product of numbers on empty array to be $ 1 $ .
输入输出样例
输入样例 #1
5
4
1 2 -1 2
3
1 1 -2
5
2 0 -2 2 -1
3
-2 -1 -1
3
-1 -2 -2
输出样例 #1
0 2
3 0
2 0
0 1
1 0