CodeForces - 1301B B - Motarack's Birthday

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 (0≤k≤1090≤k≤109) 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 |ai−ai+1||ai−ai+1| for all 1≤i≤n−11≤i≤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?

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer nn (2≤n≤1052≤n≤105) — the size of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (−1≤ai≤109−1≤ai≤109). If ai=−1ai=−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 4⋅1054⋅105.

Output

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 (0≤k≤1090≤k≤109) 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.

Example

Input

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

Output

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

Note

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≤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].

  • |a1−a2|=|6−6|=0|a1−a2|=|6−6|=0;
  • |a2−a3|=|6−9|=3|a2−a3|=|6−9|=3;
  • |a3−a4|=|9−6|=3|a3−a4|=|9−6|=3;
  • |a4−a5|=|6−3|=3|a4−a5|=|6−3|=3;
  • |a5−a6|=|3−6|=3|a5−a6|=|3−6|=3.

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

坑点挺多的一道题

注意初始化 最大1e9最小为0不能为负

#include<bits/stdc++.h>
int t;
int n;
using namespace std;
int a[100005];
void solve(){
    cin >> n;
    int mx = 0;
    int mi = 1e9;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    a[0] = -1;
    a[n + 1] = -1;
    for(int i = 1; i <= n; i++){
        if(a[i] == -1){
            if(a[i - 1] != -1){
                mx = max(mx, a[i - 1]);
                mi = min(mi, a[i - 1]);    
            }
            if(a[i + 1] != -1){
                mx = max(mx, a[i + 1]);
                mi = min(mi, a[i + 1]);                
            }
            
        }
    }
    int cnt = (mx + mi) >> 1;
    int ans = 0;
    for(int i = 1; i <= n; i++){//注意从1开始a[0]不能为cnt, wa了好几发
        if(a[i] == -1){
            a[i] = cnt;
        }
        if(i != 1){
            ans = max(abs(a[i] - a[i - 1]), ans);
        }
    }
    cout << ans << " " << cnt << endl;
}

int main(){
    cin >> t;
    while(t--){
        solve();
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值