-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
116 lines (101 loc) · 3.03 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/// by ahmed_drawy 20/12/19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
using namespace std;
#define ll long long
#define inN(arr , n) for(int i = 0 ; i< n ; ++i) cin>>arr[i];
#define lp(i,start , end) for(int i = start ; i<end ; ++i)
#define sz(v) (int)((v).size())
#define clr(v,d) memset(v , d , sizeof(v));
#define pii pair<int, int>
#define vii vector<ll>
#define vi vector<int>
#define endl '\n'
#define debug(x) cerr << x<<endl;
const double EPS = (1e-7);
void smile() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);
// freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);
#endif
}
int dcmp(double x, double y) { return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
int randomF() {
return (rand() * RAND_MAX + rand()) % 1000000;
}
ll MOD =(ll) 1e9 +7 ;
int mod(ll x){
return (x%MOD + MOD)%MOD;
}
long long add(long long x, long long y)
{
x += y;
while(x >= MOD)
x -= MOD;
while(x < 0)
x += MOD;
return x;
}
ll multipy(ll x , ll y ){
return ((x%MOD) *(y%MOD))%MOD;
}
long long power(long long base, int exp)
{
if (!exp)
return 1LL;
ll sq = power(base, exp/2);
sq = (sq * sq)%MOD;
if (exp&1)
sq = (sq * base)%MOD;
return sq;
}
bool compareT(pair<int , int > & a , pair<int ,int > &b){
if(a.first != b.first)
return a.first <b.first ;
return a.second< b.second ;
}
double dist(int x , int y , int a , int b){
return sqrt( (x-a)*(x-a) + (y-b)*(y-b));
}
bool isPalindrome (string s , int m ){
for (int i = 0; i <m/2 ; ++i) {
if(s[i] != s[m-i-1])
return false ;
}
return true;
}
int main(){
smile();
int t ;cin >> t ;
while(t--) {
int n ; cin >> n ;
vi vec(n );
vector<int >vec2;
vector<int >vec3;
for (int i = 0; i <n ; ++i)
cin >> vec[i];
int mx= -INT_MAX , mn = INT_MAX;
for (int i = 0; i <n ; ++i) {
if(i && vec[i-1] != -1 && vec[i]== -1){
mn = min(mn , vec[i-1]) ;
mx = max(mx , vec[i-1]) ;
}
if(i < n-1 && vec[i+1] != -1 &&vec[i] == -1 ) {
mn = min(mn, vec[i + 1]);
mx = max(mx, vec[i + 1]);
}
}
int res= (mx + mn )/2 ;
int ans = 0 ;
for (int j = 0; j <n ; ++j) {
if(vec[j] == -1)vec[j] = res;
if(j) ans = max(ans , abs(vec[j] - vec[j-1]) );
}
cout << ans << " " << res << endl;
}
}