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 ...
随机推荐
- softmax-Fork
softmax和分类模型 内容包含: softmax回归的基本概念 如何获取Fashion-MNIST数据集和读取数据 softmax回归模型的从零开始实现,实现一个对Fashion-MNIST训练集 ...
- Django_连接MySQL
1. 在Settings中修改 2. 创建数据库 3. 连接mysql 4. pymysql 4.1 安装pymysql 在项目的init文件中添加 Django2.2 不需要伪装
- Oracle创表操作记录
Oracle表操作 --主键,复合主键 create table example (id number primary key, name varchar2(20)); create table ex ...
- IntelliJ IDEA 2017.3尚硅谷-----自动导包
- cef源码分析之cefsimple
下面是cefsimple的入口代码,主要分成两个部分 // Entry point function for all processes. int APIENTRY wWinMain(HINSTANC ...
- 数据提取之JSON与JsonPATH
数据提取之JSON与JsonPATH JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适 ...
- 自定义控件之绘图篇(四):canvas变换与操作
具体操作见下面链接: http://blog.csdn.net/harvic880925/article/details/39080931/
- python中字符串的四种表达方式
今天在学习python的基础的内容,学习在python中如何操作字符串,在此记录下. 主要是python中字符串的几种表达,表示方式. python的几种表达方式 1 使用单引号扩起来字符串 > ...
- 面试问烂的 Spring AO,全文详解
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- 去除移动端苹果手机(ios)的input默认样式与input禁止键盘出现的方式
样式: input{-webkit-appearance: none;} 在iPhone plus点击input框出生日期时会出现如下图: 为了去掉下面那条苹果自带的,可以这样处理:在HTML中的in ...