B. Motarack's Birthday

链接:https://codeforces.ml/contest/1301/problem/B

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

Copy

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

Copy

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.

代码:

#include<bits/stdc++.h>
using namespace std;
long long t,n,l,r,x,s,k,m,min1,max1,max2;
long long a[100001];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		min1=1e9+7;
		max1=0;
		s=0;
		max2=-1;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		a[0]=a[2];
		a[n+1]=a[n-1];
		for(int i=1;i<=n;i++)
		{
			//cin>>a[i];
			if(a[i]==-1)
			s++;
			if(a[i]!=-1&&(a[i-1]==-1||a[i+1]==-1))
			{
				max1=max(max1,a[i]);
				min1=min(min1,a[i]);
			}
			if(a[i-1]!=-1&&a[i]!=-1)
			{
				max2=max(max2,abs(a[i]-a[i-1]));
			}
			if(a[i+1]!=-1&&a[i]!=-1)
			{
				max2=max(max2,abs(a[i]-a[i+1]));
			}
		}
		if(max2==-1)
		{
			if(s!=n)
			{
				k=(max1+min1)/2;
				m=max(max1-k,k-min1);
				cout<<m<<" "<<k<<endl;
			}
			else
			{
				cout<<0<<" "<<0<<endl;
			}
		}
		else
		{
			k=(max1+min1)/2;
			m=max(max1-k,k-min1);
			cout<<max(m,max2)<<" "<<k<<endl;
		} 
	}
}

 

全部评论

相关推荐

我的offer呢😡:这不才9月吗,26到明年毕业前能一直找啊,能拿下提前批,转正的,offer打牌的都是有两把刷子的,为什么非要跟他们比。如果别人是9本硕+金牌+好几段大厂实习呢?如果别人是双非通天代呢?如果别人是速通哥呢?,做好自己就行了,我们做不到他们一样提前杀死比赛,但晚点到终点也没啥关系吧
双非应该如何逆袭?
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务