CF1660D.Maximum Product Strikes Back

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa consisting of nn integers. For each ii ( 1in1 \le i \le n ) the following inequality is true: 2ai2-2 \le a_i \le 2 .

You can remove any number (possibly 00 ) of elements from the beginning of the array and any number (possibly 00 ) 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 00 ) should be assumed to be 11 .

输入格式

The first line of input data contains an integer tt ( 1t1041 \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 nn ( 1n21051 \le n \le 2 \cdot 10^5 ) —the length of array aa .

The next line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( ai2|a_i| \le 2 ) — elements of array aa .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output two non-negative numbers xx and yy ( 0x+yn0 \le x + y \le n ) — such that the product (multiplication) of the array numbers, after removing xx elements from the beginning and yy 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 11 .

输入输出样例

  • 输入#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

说明/提示

In the first case, the maximal value of the product is 22 . Thus, we can either delete the first three elements (obtain array [2][2] ), or the last two and one first element (also obtain array [2][2] ), or the last two elements (obtain array [1,2][1, 2] ). Thus, in the first case, the answers fit: "3 0", or "1 2", or "0 2".

In the second case, the maximum value of the product is 11 . Then we can remove all elements from the array because the value of the product on the empty array will be 11 . So the answer is "3 0", but there are other possible answers.

In the third case, we can remove the first two elements of the array. Then we get the array: [2,2,1][-2, 2, -1] . The product of the elements of the resulting array is (2)2(1)=4(-2) \cdot 2 \cdot (-1) = 4 . This value is the maximum possible value that can be obtained. Thus, for this case the answer is: "2 0".

首页