Codeforces Round #619 (Div. 2) 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
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 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的更多相关文章
- Codeforces Round #619 (Div. 2) A~D题解
		
最近网课也开始了,牛客上一堆比赛题目也没补,所以就D题后面的也懒得补了 A.Three String 水题 #include <cstdio> #include <cstring&g ...
 - Codeforces Round #619 (Div. 2)
		
A. Three Strings 题意:给三个长度相同的非空字符串abc,依次将c中的每个字符和a或者b中对应位置的字符进行交换,交换必须进行,问能否使得ab相同. 思路:对于每一个位置,如果三个字符 ...
 - Codeforces Round #619 (Div. 2)E思维+二维RMQ
		
题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...
 - Codeforces Round #619 (Div. 2)D(模拟)
		
先把一种最长路线记录下来,根据k的大小存到ans中相应的答案再输出 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using n ...
 - Codeforces Round #619 (Div. 2)C(构造,容斥)
		
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::syn ...
 - 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 ...
 - 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 ...
 - 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 ...
 - Codeforces Round #354 (Div. 2) ABCD
		
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
 
随机推荐
- Navicat图形更改表结构的时,设置外键时出现1452错误
			
原文地址:http://www.mamicode.com/info-detail-1296600.html 提示1452错误,如下图所示. 然后百度了一下,得到了一个靠谱的答案: 这是因为表设置了外键 ...
 - library 中的internal power为何为负值?
			
下图是library中一个寄存器Q pin 的internal_power table, 表中该pin 的internal power 大多都是负值.其实library 中的internal_powe ...
 - Linux中内容查看命令"大PK"
			
众所周知linux中命令cat.more.less均可用来查看文件内容,当然还有我们"非主流"的vim以及使用较少的head.tail.tac. 下面我将介绍各种命令的用法及对比. ...
 - c++对象的内存模式
			
#include <iostream> using namespace std; class Obj { private: int* a; public: int* ga() { retu ...
 - SQL通过Datatable更新数据库表内容
			
SQL通过Datatable更新数据库表内容 //要注意的一点是在Select语句中要选择的列中必须包含主键的列,此外不支持多表连接查询 DataTable dt = new DataTable( ...
 - Windows10_64位下upload-labs靶场搭建+phpstudy_v8.1安装教程
			
之前介绍了Windows10_64位搭建WampServer的教程,这一次再来水一篇phpstudy的搭建教程.哈哈哈. 顺便安装一下upload-labs,搭着玩玩~ 操作 ...
 - linux用字符模式修改权限
			
-rw-r--r-- tt.htm 从第二个字符起rw是说用户apple有读.写权,没有运行权,接着的r--表示用户组users只有读权限,没有运行权,最后的r--指其他人 (others)只有读权 ...
 - js 实现文字转音频播放
			
var msg = new SpeechSynthesisUtterance("hello World"); console.log(msg); window.speechSynt ...
 - Django中csrf_token验证原理
			
我多年没维护的博客园,有一篇初学Django时的笔记,记录了关于django-csrftoekn使用笔记,当时几乎是照抄官网的使用示例,后来工作全是用的flask.博客园也没有维护.直到我的博客收到了 ...
 - vue音乐播放器
			
利用vue写一个简单的音乐播放器,包括功能有歌曲搜索.歌曲播放.歌曲封面.歌曲评论.播放动画.mv播放六个功能. <template> <div class="wrap&q ...