CF1301B.Motarack's Birthday

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array aa of nn non-negative integers.

Dark created that array 10001000 years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn't have much time so he wants to choose an integer kk ( 0k1090 \leq k \leq 10^{9} ) and replaces all missing elements in the array aa with kk .

Let mm be the maximum absolute difference between all adjacent elements (i.e. the maximum value of aiai+1|a_i - a_{i+1}| for all 1in11 \leq i \leq n - 1 ) in the array aa after Dark replaces all missing elements with kk .

Dark should choose an integer kk so that mm is minimized. Can you help him?

输入格式

The input consists of multiple test cases. The first line contains a single integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer nn ( 2n1052 \leq n \leq 10^{5} ) — the size of the array aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai109-1 \leq a_i \leq 10 ^ {9} ). If ai=1a_i = -1 , then the ii -th integer is missing. It is guaranteed that at least one integer is missing in every test case.

It is guaranteed, that the sum of nn for all test cases does not exceed 41054 \cdot 10 ^ {5} .

输出格式

Print the answers for each test case in the following format:

You should print two integers, the minimum possible value of mm and an integer kk ( 0k1090 \leq k \leq 10^{9} ) that makes the maximum absolute difference between adjacent elements in the array aa equal to mm .

Make sure that after replacing all the missing elements with kk , the maximum absolute difference between adjacent elements becomes mm .

If there is more than one possible kk , you can print any of them.

输入输出样例

  • 输入#1

    7
    5
    -1 10 -1 12 -1
    5
    -1 40 35 -1 35
    6
    -1 -1 9 -1 3 -1
    2
    -1 -1
    2
    0 -1
    4
    1 -1 3 -1
    7
    1 -1 7 5 2 -1 5

    输出#1

    1 11
    5 35
    3 6
    0 42
    0 0
    1 2
    3 4

说明/提示

In the first test case after replacing all missing elements with 1111 the array becomes [11,10,11,12,11][11, 10, 11, 12, 11] . The absolute difference between any adjacent elements is 11 . It is impossible to choose a value of kk , such that the absolute difference between any adjacent element will be 0\leq 0 . So, the answer is 11 .

In the third test case after replacing all missing elements with 66 the array becomes [6,6,9,6,3,6][6, 6, 9, 6, 3, 6] .

  • a1a2=66=0|a_1 - a_2| = |6 - 6| = 0 ;
  • a2a3=69=3|a_2 - a_3| = |6 - 9| = 3 ;
  • a3a4=96=3|a_3 - a_4| = |9 - 6| = 3 ;
  • a4a5=63=3|a_4 - a_5| = |6 - 3| = 3 ;
  • a5a6=36=3|a_5 - a_6| = |3 - 6| = 3 .

So, the maximum difference between any adjacent elements is 33 .

首页