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 ;
}

Codeforces Round #619 (Div. 2) B. Motarack's Birthday的更多相关文章

  1. Codeforces Round #619 (Div. 2) A~D题解

    最近网课也开始了,牛客上一堆比赛题目也没补,所以就D题后面的也懒得补了 A.Three String 水题 #include <cstdio> #include <cstring&g ...

  2. Codeforces Round #619 (Div. 2)

    A. Three Strings 题意:给三个长度相同的非空字符串abc,依次将c中的每个字符和a或者b中对应位置的字符进行交换,交换必须进行,问能否使得ab相同. 思路:对于每一个位置,如果三个字符 ...

  3. Codeforces Round #619 (Div. 2)E思维+二维RMQ

    题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...

  4. Codeforces Round #619 (Div. 2)D(模拟)

    先把一种最长路线记录下来,根据k的大小存到ans中相应的答案再输出 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using n ...

  5. Codeforces Round #619 (Div. 2)C(构造,容斥)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::syn ...

  6. Codeforces Round #619 (Div. 2) Ayoub's function

    Ayoub thinks that he is a very smart person, so he created a function f(s)f(s) , where ss is a binar ...

  7. Codeforces Round #619 (Div. 2) A. Three Strings

    You are given three strings aa , bb and cc of the same length nn . The strings consist of lowercase ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. java程序启动参数

    例如 启动进程如下 /home/work/noah/ccs/jc-controller/jdk1.7.0_55/bin/java -Xmx4096m -Xms4096m -Xmn1024m -XX:+ ...

  2. CentOS 7 如何设置为eth0网卡

    参考文章https://www.linuxidc.com/Linux/2017-06/144973.htm 主要方法 1) 安装的时候,在内核选项中加上net.ifnames=0 biosdevnam ...

  3. selenium + phantomJS 常用方法总结

    0x01 初始化: dcap = dict(DesiredCapabilities.PHANTOMJS)  #一些属性的设置 dcap["phantomjs.page.settings.lo ...

  4. JS字符串的不可变性

    js中的字符串特性->不可变性,字符串的值是不可变的 1.改变字符串中的字符 var str = "hello"; str[1] = "W"; conso ...

  5. PostGreSql - 提取jsonb数据

    本文主要介绍如何在PostGreSql中提取出jsonb类型字段中的某个key的值 参考:https://www.cnblogs.com/mywebnumber/p/5551092.html 一.简单 ...

  6. win10编译OPenBlas

    之前没有编译过OpenBlas,今天试了一下. 与参考博客不同之处,我的系统是win10,opencOpenBlas版本0.2.14,Visual Studio版本15. 编译使用MSYS2安装min ...

  7. Go递归函数

    package main import "fmt" func main() { /* 递归函数(recursion):一个函数自己调用自己,就叫做递归函数. 递归函数要有一个出口, ...

  8. 时间戳,日期,string互转

    import timeimport datetimeimport operatordef makeStamp(y,m,d,format='%Y-%m-%d'): """m ...

  9. 使用Spring框架整合Java Mail

    我的博客名为黑客之谜,今天演示的案例中会出现我的邮箱,还不赶紧收藏!我现在是小白,但是随着时间的流逝,我会逐渐向大神走进,所以,喜欢我的,或者喜欢大神的,点一波关注吧!顺便说一下,双十二快到了,有什么 ...

  10. 零基础入门python爬虫(一)

    ✍写在前面: 欢迎加入纯干货技术交流群Disaster Army:317784952 接到5月25日之前要交稿的任务我就一门心思想写一篇爬虫入门的文章,可是我并不会.还好有将近一个月的时间去学习,于是 ...