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 大意是给一个缺少一些数的序列,要求在每一个空缺的位置添上一个相同的数,使得这个序列中相邻两数之差的最大绝对值尽可能小。
首先把这个序列读入,然后遍历一遍,统计两个量:与空缺位置相邻的数里的最大值mmax和最小值mmin。
为什么要相邻呢?因为如果一个数不和空缺位置相邻的话,空缺位置不论填什么都和这个数没有关系,最后处理的时候再看它就行了。
然后令k=(mmax+mmin)/2,再次遍历一遍序列先把空缺位置填上k然后计算相邻两数之差并更新答案。
#include <bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
scanf("%d",&n);
int i;
memset(a,,sizeof(a));
int mmax=-;
int mmin=;
int cnt_neg=;
for(i=;i<=n;i++)scanf("%d",&a[i]);
for(i=;i<=n;i++)
{
//scanf("%d",&a[i]);必须要全读进去再处理,要不然a[i+1]还是0
if(a[i]==-)cnt_neg++;
if(i>&&a[i]==-&&a[i-]!=-)
{
mmax=max(mmax,a[i-]);
mmin=min(mmin,a[i-]);
}
if(i<n&&a[i]==-&&a[i+]!=-)
{
mmax=max(mmax,a[i+]);
mmin=min(mmin,a[i+]);
}
}
if(cnt_neg==n)
{
cout<<<<' '<<<<endl;
continue;
}
int k=(mmax+mmin)/;
int m=;
for(i=;i<=n;i++)if(a[i]==-)a[i]=k;
for(i=;i<=n;i++)
{
m=max(m,abs(a[i]-a[i-]));
}
cout<<m<<' '<<k<<endl;
}
return ;
}

最新文章

  1. [LeetCode] Combination Sum IV 组合之和之四
  2. redis 密码配置
  3. 2-06使用SQL语句创建数据库3
  4. 单机安装TFS(转载)
  5. cocos2dx 坐标系 -转
  6. exynos 4412 电源管理芯片PMIC 的配置及使用方法
  7. 原生js判断是否有某个class,如果有就删掉,没有加上
  8. Firemonkey使用iOS的第三方静态库(Link Binary With Libraries)
  9. 在MFC程序中使用XML文件配置工具栏
  10. 淘淘商城_day11_课堂笔记
  11. Polipo
  12. 向EXECL文件中导入数据的同时插入图片
  13. YII2框架下使用PHPExcel导出柱状图
  14. Tomcat,eclipse热部署的三种方式
  15. ant的设置properties
  16. ajax 上传文件,监听进度(progress)
  17. web开发中xml的内容
  18. JavaSE基础知识(3)—流程控制结构
  19. inode占用100%时硬盘无法写入文件故障处理
  20. Python 爬虫-正则表达式(补)

热门文章

  1. 等差数列Arithmetic Progressions题解(USACO1.4)
  2. Redis 基本数据类型以及相应操作
  3. MODULE BUILD FAILED: ERROR: COULDN’T FIND PRESET “ES2015” RELATIVE TO DIRECTORY
  4. 【转载】Mapreduce实现自定义的InputFormat
  5. C位域操作
  6. MSYS2与mingw32和mingw64的安装
  7. A. DZY Loves Chessboard
  8. angular 页面中引入静态 PDF 文件
  9. 连接mongodb服务
  10. Codeforces Gym 102392F Game on a Tree (SEERC2019 F题) 题解