description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) cnt = 0 u = -1 for i in arr: if i != -1: cnt += 1 u = i if cnt == 0: print(0, 0) elif cnt == 1: print(0, u) else: maxx = max(arr) m = 10**10 for i in arr: if i != -1: m = min(m, i) l, h = m, maxx temp = arr[:] for i in range(n): if temp[i] == -1: temp[i] = l t = -1 for i in range(1, n): t = max(t, abs(temp[i] - temp[i - 1])) val1 = t t = -1 temp = arr[:] for i in range(n): if temp[i] == -1: temp[i] = h for i in range(1, n): t = max(t, abs(temp[i] - temp[i - 1])) val2 = t while l < h: m = (l + h) // 2 temp = arr[:] for i in range(n): if temp[i] == -1: temp[i] = m t = -1 for i in range(1, n): t = max(t, abs(temp[i] - temp[i - 1])) if val1 > val2: l = m val1 = t else: h = m val2 = t if abs(h - l) == 1: break if val1 < val2: print(val1, l) else: print(val2, h)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) A = list(map(int, input().split())) L = [] m = 0 now = A[0] for a in A[1:]: if now == -1: if a != -1: L.append(a) now = a elif a == -1: L.append(now) now = -1 else: m = max(m, abs(a - now)) now = a L.sort() if L: k = (L[-1] + L[0]) // 2 m = max(m, L[-1] - k) else: k = 0 m = 0 print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for ttt in range(int(input())): n = int(input()) arr = list(map(int, input().split())) minus_one = arr.count(-1) if n == minus_one: print(0, 0) continue res = [] for i in range(n): if arr[i] == -1: if i == 0: if arr[i + 1] != -1: res.append(arr[i + 1]) elif i == n - 1: if arr[i - 1] != -1: res.append(arr[i - 1]) else: if arr[i - 1] != -1: res.append(arr[i - 1]) if arr[i + 1] != -1: res.append(arr[i + 1]) maxi = max(res) mini = min(res) mm = (mini + maxi) // 2 for i in range(n): if arr[i] == -1: arr[i] = mm maxiiii = 0 for i in range(n - 1): maxiiii = max(maxiiii, abs(arr[i] - arr[i + 1])) print(maxiiii, mm)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) ar = [-2] + a + [-2] r = [] for i in range(1, n + 2): if ar[i] > -1 and (ar[i - 1] == -1 or ar[i + 1] == -1): r.append(ar[i]) ans, m = 0, 0 if not r == []: ans = (max(r) + min(r)) // 2 a = [*map(lambda x: ans if x == -1 else x, a)] m = max([abs(a[i] - a[i - 1]) for i in range(1, n)]) print(m, ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR LIST ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [] maa = 0 if a[0] != -1 and a[1] == -1: b.append(a[0]) if a[-1] != -1 and a[-2] == -1: b.append(a[-1]) for i in range(1, n - 1): if a[i] != -1 and (a[i - 1] == -1 or a[i + 1] == -1): b.append(a[i]) for i in range(1, n): if a[i - 1] != -1 and a[i] != -1: maa = max(maa, abs(a[i] - a[i - 1])) if b == []: print(0, 0) continue ma = max(b) mi = min(b) k = (ma + mi) // 2 m = max(abs(ma - k), abs(mi - k)) print(max(m, maa), k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def go(): n = int(input()) a = list(map(int, input().split())) mn, mx = 100000000000, -1 m = -1 for i in range(n): if i > 0 and a[i] != -1 and a[i - 1] != -1: m = max(m, abs(a[i] - a[i - 1])) if a[i] == -1: if i > 0 and a[i - 1] != -1: mn = min(mn, a[i - 1]) mx = max(mx, a[i - 1]) if i < n - 1 and a[i + 1] != -1: mn = min(mn, a[i + 1]) mx = max(mx, a[i + 1]) if mx == -1: return "0 0" k = (mn + mx) // 2 return f"{max(k - mn, mx - k, m)} {k}" t = int(input()) for _ in range(t): print(go())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for i in range(int(input())): n = int(input()) a = [int(s) for s in input().split()] b = [] if a[0] != -1 == a[1]: b.append(a[0]) for j in range(1, n - 1): if a[j] != -1 and (a[j - 1] == -1 or a[j + 1] == -1): b.append(a[j]) if a[-1] != -1 == a[-2]: b.append(a[-1]) if len(b) == 0: print(0, 0) else: mi = min(b) ma = max(b) k = (mi + ma) // 2 md = 0 for j in range(len(a) - 1): md = max( md, abs((k if a[j] < 0 else a[j]) - (k if a[j + 1] < 0 else a[j + 1])) ) print(md, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def check(a: list, m: int, n: int) -> bool: l = -1 r = int(1000000000.0) for i in range(1, n + 1): if a[i] == -1: lt = rt = 0 if a[i - 1] == -1 and a[i + 1] == -1: continue elif a[i - 1] == -1 and a[i + 1] != -1: lt = a[i + 1] - m rt = a[i + 1] + m elif a[i - 1] != -1 and a[i + 1] == -1: lt = a[i - 1] - m rt = a[i - 1] + m else: rt = min(a[i - 1], a[i + 1]) + m lt = max(a[i + 1], a[i - 1]) - m l = max(l, lt) r = min(r, rt) if l > r: return False elif a[i - 1] != -1 and abs(a[i - 1] - a[i]) > m: return False global k k = r return True for _ in range(int(input())): n = int(input()) a = [-1] + list(map(int, input().split())) + [-1] lm = k = 0 rm = int(1000000000.0) while lm < rm: mid = lm + rm >> 1 if check(a, mid, n): rm = mid else: lm = mid + 1 print(rm, k)
FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR RETURN NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) tot, cnt = 0, 0 ans = -1000000009 ma, mi = -1000000009, 1000000009 for i in range(n): if a[i] != -1: if i and a[i - 1] == -1 or i + 1 < n and a[i + 1] == -1: tot += a[i] cnt += 1 if i and a[i - 1] != -1: ans = max(ans, abs(a[i] - a[i - 1])) if i + 1 < n and a[i + 1] != -1: ans = max(ans, abs(a[i] - a[i + 1])) else: if i and a[i - 1] != -1: mi = min(mi, a[i - 1]) ma = max(ma, a[i - 1]) if i + 1 < n and a[i + 1] != -1: mi = min(mi, a[i + 1]) ma = max(ma, a[i + 1]) if cnt: tot = (ma + mi) // 2 else: tot, ma, mi = 0, 0, 0 print(max(ans, ma - tot, tot - mi), tot)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def f(n, A, x): B = A[:] for i in range(n): if B[i] == -1: B[i] = x m = 0 for i in range(n - 1): m = max(abs(B[i] - B[i + 1]), m) return m t = int(input()) while t > 0: t = t - 1 n = int(input()) a = input() A = list(map(int, list(a.split()))) l = min(A) h = max(A) while l <= h: mid = (l + h) // 2 if f(n, A, mid) <= f(n, A, mid - 1) and f(n, A, mid) <= f(n, A, mid + 1): if mid < 0: print(f(n, A, 0), end=" ") print(0) elif mid > 10**9: prin(f(n, A, 10**9), end=" ") print(10**9) else: print(f(n, A, mid), end=" ") print(mid) break elif f(n, A, mid) > f(n, A, mid - 1): h = mid - 1 elif f(n, A, mid) < f(n, A, mid - 1): l = mid + 1
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER NUMBER STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**18 MOD = 10**9 + 7 for _ in range(INT()): N = INT() A = LIST() mx = 0 S = set() for i in range(N - 1): if A[i] != -1 and A[i + 1] != -1: mx = max(mx, abs(A[i] - A[i + 1])) if A[i] != -1 and A[i + 1] == -1: S.add(A[i]) if A[i] == -1 and A[i + 1] != -1: S.add(A[i + 1]) if S: li = sorted(S) k = (li[0] + li[-1]) // 2 m = max(max(li[-1] - k, k - li[0]), mx) print(m, k) else: print(mx, 0)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys input = sys.stdin.buffer.readline def print(*vals): sys.stdout.write(" ".join(map(str, vals)) + "\n") def max_diff(integers, k, n): max_diff = 0 for i in range(n - 1): if integers[i] == -1 and integers[i + 1] != -1: max_diff = max(max_diff, abs(k - integers[i + 1])) elif integers[i + 1] == -1 and integers[i] != -1: max_diff = max(max_diff, abs(integers[i] - k)) else: max_diff = max(max_diff, abs(integers[i] - integers[i + 1])) return max_diff def prog(): for _ in range(int(input())): n = int(input()) integers = list(map(int, input().split())) L = 0 R = 10**9 while L != R: diff = (R - L) // 3 m1 = L + diff m2 = R - diff val1 = max_diff(integers, m1, n) val2 = max_diff(integers, m2, n) if val1 > val2: L = m1 + 1 else: R = m2 - 1 print(max_diff(integers, R, n), R) prog()
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] b = [] for i in range(len(a)): if a[i] == -1: if i == 0: if a[1] != -1: b.append(a[1]) elif i == len(a) - 1: if a[n - 2] != -1: b.append(a[n - 2]) else: if a[i - 1] != -1: b.append(a[i - 1]) if a[i + 1] != -1: b.append(a[i + 1]) temp = -1 for i in range(1, len(a)): if a[i] != -1 and a[i - 1] != -1: temp = max(temp, abs(a[i - 1] - a[i])) if len(b) == 0: print(max(temp, 0), 1) continue elif len(b) == 1: print(max(0, temp), b[0]) continue k = min(b) + int((max(b) - min(b)) / 2) ans = max(temp, max(b) - k, k - min(b)) print(ans, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for T in range(t): n = int(input()) a = list(map(int, input().split())) if max(a) == -1: print(0, 79) continue mi = max(a) ma = 0 for i in range(n): if a[i] == -1: if i > 0 and a[i - 1] != -1: mi = min(mi, a[i - 1]) ma = max(ma, a[i - 1]) if i < n - 1 and a[i + 1] != -1: mi = min(mi, a[i + 1]) ma = max(ma, a[i + 1]) k = (ma + mi) // 2 a = [(k if i == -1 else i) for i in a] m = max([abs(a[i - 1] - a[i]) for i in range(1, n)]) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) st = [] mx = 0 for i in range(n): if a[i] == -1: if i + 1 < n and a[i + 1] != -1: st.append(a[i + 1]) if i - 1 >= 0 and a[i - 1] != -1: st.append(a[i - 1]) if i > 0 and a[i] != -1 and a[i - 1] != -1 and abs(a[i] - a[i - 1]) > mx: mx = abs(a[i] - a[i - 1]) st.sort() if len(st): mx1 = (st[0] + st[-1]) // 2 else: mx1 = 0 if len(st): mx = max(mx, mx1 - st[0], st[-1] - mx1) print(mx, mx1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for ii in range(t): n = int(input()) A = list(map(int, input().split())) B = [] ab = 0 for i in range(n - 1): if A[i] == -1 and A[i + 1] != -1: B.append(A[i + 1]) elif A[i] != -1 and A[i + 1] == -1: B.append(A[i]) else: ab = max(ab, abs(A[i] - A[i + 1])) B.sort() b = 0 ab2 = 0 if len(B) > 0: b = (B[-1] - B[0] + 1) // 2 + B[0] ab2 = max(abs(B[-1] - b), abs(B[0] - b)) print(max(ab, ab2), b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) p = [] for i in range(1, n - 1): if (l[i - 1] == -1 or l[i + 1] == -1) and l[i] != -1: p.append(l[i]) if l[1] == -1 and l[0] != -1: p.append(l[0]) if l[n - 2] == -1 and l[n - 1] != -1: p.append(l[n - 1]) if p == []: print(0, 0) else: if len(p) == 1: k = p[0] else: k = (max(p) + min(p)) // 2 for i in range(n): if l[i] == -1: l[i] = k m = 0 for i in range(1, n): if abs(l[i] - l[i - 1]) > m: m = abs(l[i] - l[i - 1]) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) minAdj = max(a) maxAdj = min(a) if a[0] == -1: if a[1] != -1: if a[1] > maxAdj: maxAdj = a[1] if a[1] < minAdj: minAdj = a[1] if a[n - 1] == -1: if a[n - 2] != -1: if a[n - 2] > maxAdj: maxAdj = a[n - 2] if a[n - 2] < minAdj: minAdj = a[n - 2] for i in range(1, n - 1): if a[i] == -1: if a[i - 1] != -1: if a[i - 1] > maxAdj: maxAdj = a[i - 1] if a[i - 1] < minAdj: minAdj = a[i - 1] if a[i + 1] != -1: if a[i + 1] > maxAdj: maxAdj = a[i + 1] if a[i + 1] < minAdj: minAdj = a[i + 1] if minAdj == -1 and maxAdj == -1: minAdj = 0 maxAdj = 0 m = 0 k = (maxAdj + minAdj) // 2 if a[0] == -1: a[0] = k for i in range(1, n): if a[i] == -1: a[i] = k m = max(abs(a[i] - a[i - 1]), m) print(*[m, k])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) max1, min1 = 0, 10**9 for q in range(len(a)): if a[q] != -1: if q != n - 1 and a[q + 1] == -1: max1 = max(max1, a[q]) min1 = min(min1, a[q]) if q != 0 and a[q - 1] == -1: max1 = max(max1, a[q]) min1 = min(min1, a[q]) ans, ans1 = (min1 + max1) // 2, 0 for q in range(n - 1): if a[q] == -1 and a[q + 1] == -1: continue elif a[q] == -1: ans1 = max(ans1, abs(ans - a[q + 1])) elif a[q + 1] == -1: ans1 = max(ans1, abs(ans - a[q])) else: ans1 = max(ans1, abs(a[q] - a[q + 1])) print(ans1, ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for i in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ls = [] for i in range(n): if arr[i] == -1: continue if i < n - 1 and arr[i + 1] == -1 or i > 0 and arr[i - 1] == -1: ls.append(arr[i]) if ls == []: ls.append(0) var = (min(ls) + max(ls)) // 2 m = 0 for i in range(n - 1): if arr[i] == -1: arr[i] = var if arr[i + 1] == -1: arr[i + 1] = var ans = abs(arr[i] - arr[i + 1]) m = max(m, ans) print(m, var)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys read = lambda: list(map(int, sys.stdin.readline().strip().split())) for _ in range(int(input())): n = int(input()) m1 = 10**10 m2 = -1 diff = 0 last = -1 a = read() n1 = n - 1 for ind, i in enumerate(a): if i >= 0 and last >= 0: diff = max(diff, abs(i - last)) last = i if i >= 0 and (ind > 0 and a[ind - 1] == -1 or ind < n1 and a[ind + 1] == -1): if m1 > i: m1 = i if m2 < i: m2 = i if m1 == 10**10 or m2 == -1: print(0, 23) continue k = (m1 + m2) // 2 print(max(diff, m2 - k), k)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) if a.count(-1) == len(a): print(0, 1) else: d = list() for i in range(n): if i + 1 < n and a[i] == -1 and a[i + 1] != -1: d.append(a[i + 1]) if i - 1 >= 0 and a[i] == -1 and a[i - 1] != -1: d.append(a[i - 1]) m = 0 for i in range(n - 1): if a[i] != -1 and a[i + 1] != -1: m = max(m, abs(a[i] - a[i + 1])) d.sort() s = d[-1] + d[0] if s % 2 == 0: k = s // 2 for i in range(n): if a[i] == -1: a[i] = k for i in range(1, n): m = max(m, abs(a[i] - a[i - 1])) print(m, k) else: t1 = s // 2 t2 = t1 + 1 v = a.copy() for i in range(n): if a[i] == -1: a[i] = t1 if v[i] == -1: v[i] = t2 q = m for i in range(1, n): m = max(m, abs(a[i] - a[i - 1])) q = max(q, abs(v[i] - v[i - 1])) if m < q: print(m, t1) else: print(q, t2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def main(): t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = set() for i in range(n - 1): if a[i] == -1 and a[i + 1] != -1: s.add(i + 1) elif a[i] > -1 and a[i + 1] == -1: s.add(i) if len(s) == 0: print("0 0") else: b = [a[i] for i in s] k1 = (min(b) + max(b)) // 2 k2 = (min(b) + max(b) + 1) // 2 c = a[:] for i, v in enumerate(a): if v == -1: c[i] = k1 a[i] = k2 m1 = -100 m2 = -100 for i in range(n - 1): m1 = max(m1, abs(c[i] - c[i + 1])) m2 = max(m2, abs(a[i] - a[i + 1])) if m1 <= m2: print(m1, k1) else: print(m2, k2) return main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) sm = 0 for i in range(n - 1): if l[i] != -1 and l[i + 1] != -1: m = abs(l[i] - l[i + 1]) sm = max(m, sm) r = [] if l[0] == -1 and l[1] != -1: r.append(l[1]) if l[n - 1] == -1 and l[n - 2] != -1: r.append(l[n - 2]) for i in range(1, n - 1): if l[i] == -1: if l[i + 1] != -1: r.append(l[i + 1]) if l[i - 1] != -1: r.append(l[i - 1]) r.sort() p = len(r) if p > 0: k = r[p - 1] - r[0] k = k // 2 k = k + r[0] mx = max(r[p - 1] - k, k - r[0]) else: mx = sm k = 0 sm = max(mx, sm) print(sm, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) adj = [] ans = 0 k = -1 for j in range(n - 1): if a[j] == -1: if a[j + 1] != -1: adj.append(a[j + 1]) elif a[j + 1] == -1: adj.append(a[j]) elif abs(a[j] - a[j + 1]) > ans: ans = abs(a[j] - a[j + 1]) if adj == []: print(ans, 0) continue adj.sort() if ans < adj[-1] - (adj[-1] + adj[0]) // 2: ans = adj[-1] - (adj[0] + adj[-1]) // 2 print(ans, (adj[-1] + adj[0]) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys def ceil(a, b): return -(-a // b) def answer(n, a): mnm = -1 lindx = -1 nums = set() for i in range(n): if a[i] > -1 and lindx > -1: if lindx != i - 1: m = ceil(abs(a[i] - a[lindx]), 2) else: m = abs(a[i] - a[lindx]) mnm = max(mnm, m) lindx = i elif a[i] > -1: lindx = i else: if i - 1 >= 0: nums.add(a[i - 1]) if i + 1 <= n - 1: nums.add(a[i + 1]) nums.discard(-1) if len(nums) == 0: print(0, 0) return mx = max(nums) mn = min(nums) best_k = (mx + mn) // 2 mnm_nums = mx - best_k final_m = max(mnm_nums, mnm) print(final_m, best_k) return def main(): t = int(sys.stdin.readline()) while t: n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) answer(n, a) t -= 1 return main()
IMPORT FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): x = int(input()) arr = list(map(int, input().split())) tar = [] for i in range(x - 1): if arr[i] != -1 and arr[i + 1] == -1: tar.append(arr[i]) elif arr[i] == -1 and arr[i + 1] != -1: tar.append(arr[i + 1]) if not tar: print(0, 0) else: k = (max(tar) + min(tar) + 1) // 2 m = 0 for i in range(x): if arr[i] == -1: arr[i] = k for i in range(x - 1): m = max(m, abs(arr[i] - arr[i + 1])) print(m, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for j in range(0, t): n = int(input()) s = set() a = list(map(int, input().split())) for i in range(0, n - 1): if a[i] == -1 and a[i + 1] != -1: s.add(a[i + 1]) elif a[i + 1] == -1 and a[i] != -1: s.add(a[i]) if max(a) == -1: print(0, 0) else: aa = (max(list(s)) + min(list(s))) // 2 for i in range(0, n): if a[i] == -1: a[i] = aa maxi = -1 for i in range(1, n): if maxi < abs(a[i - 1] - a[i]): maxi = abs(a[i - 1] - a[i]) print(maxi, aa)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
numTestcases = int(input()) for i in range(numTestcases): n = int(input()) array = list(map(int, input().split(" "))) cMin = 9999999999 cMax = 0 for c in range(n): if array[c] == -1: if c != 0 and array[c - 1] != -1: cMin = min(cMin, array[c - 1]) cMax = max(cMax, array[c - 1]) if c != n - 1 and array[c + 1] != -1: cMax = max(cMax, array[c + 1]) cMin = min(cMin, array[c + 1]) if cMin == 9999999999: print("0 0") else: k = (cMax - cMin) // 2 + cMin m = 0 for i in range(1, n): firstNum = array[i - 1] if firstNum == -1: firstNum = k secondNum = array[i] if secondNum == -1: secondNum = k m = max(abs(secondNum - firstNum), m) print(str(m) + " " + str(k))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def merge_neg_one(arr): merged = [] for idx, item in enumerate(arr): if idx == 0: merged.append(item) continue if merged[-1] == -1 and item == -1: continue merged.append(item) return merged def problem2(arr): arr_nonzero = list(filter(lambda x: x != -1, arr)) if len(arr_nonzero) == 0: return "0 0" candidates = [min(arr_nonzero), max(arr_nonzero)] merged = merge_neg_one(arr) for idx, item in enumerate(merged): if item == -1: if idx == 0: continue if idx == len(merged) - 1: continue if merged[idx - 1] != -1 and merged[idx + 1] != -1: candidates.append(int((merged[idx - 1] + merged[idx + 1]) / 2)) min_max_adj_diff = 1000000000 ans = None malformed = False for candidate in candidates: max_adj_diff = 0 for idx, item in enumerate(arr): if idx == len(arr) - 1: break a = arr[idx] b = arr[idx + 1] if a == -1: a = candidate if b == -1: b = candidate adj_diff = abs(a - b) if adj_diff > max_adj_diff: max_adj_diff = adj_diff if a == arr[idx] and b == arr[idx + 1]: malformed = True else: malformed = False if max_adj_diff < min_max_adj_diff: min_max_adj_diff = max_adj_diff ans = candidate if malformed: ans = min(candidates) return f"{min_max_adj_diff} {ans}" def problem2_1(arr): maxn = 0 minn = 1000000000 for idx, item in enumerate(arr): if idx > 0 and item == -1 and arr[idx - 1] != -1: if maxn < arr[idx - 1]: maxn = arr[idx - 1] if minn > arr[idx - 1]: minn = arr[idx - 1] if idx < len(arr) - 1 and item == -1 and arr[idx + 1] != -1: if maxn < arr[idx + 1]: maxn = arr[idx + 1] if minn > arr[idx + 1]: minn = arr[idx + 1] ans = int((minn + maxn) / 2) max_adj_diff = 0 for idx, item in enumerate(arr): if idx == 0: continue a = arr[idx - 1] if a == -1: a = ans b = arr[idx] if b == -1: b = ans adj_diff = abs(a - b) if adj_diff > max_adj_diff: max_adj_diff = adj_diff return f"{max_adj_diff} {ans}" N = int(input()) for i in range(N): num = input() arr = list(map(lambda x: int(x), input().split(" "))) print(problem2_1(arr))
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR STRING VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) al = list(map(int, input().split())) bl = [] for i in range(n - 1): if al[i] == -1 and al[i + 1] != -1: bl.append(al[i + 1]) elif al[i] != -1 and al[i + 1] == -1: bl.append(al[i]) bl = sorted(bl) if len(bl) == 0: print(0, 0) continue ans = (bl[0] + bl[-1]) // 2 ans2 = 0 for i in range(n - 1): if al[i] == -1: al[i] = ans if al[i + 1] == -1: al[i + 1] = ans k = abs(al[i + 1] - al[i]) ans2 = max(ans2, k) print(ans2, ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def main(): n = int(input()) a = list(map(int, input().split())) add = 0 mx = -5 mn = 1000000001 cnt = 0 for i in range(n): if i > 0 and a[i - 1] == -1 and a[i] != -1: if a[i] > mx: mx = a[i] if a[i] < mn: mn = a[i] elif i < n - 1 and a[i + 1] == -1 and a[i] != -1: if a[i] > mx: mx = a[i] if a[i] < mn: mn = a[i] avg = (mx + mn) // 2 ans = -1 for i in range(1, n): if a[i - 1] == -1: a[i - 1] = avg if a[i] == -1: a[i] = avg ans = max(ans, abs(a[i] - a[i - 1])) print(ans, avg) return def test(): t = int(input()) while t: main() t -= 1 test()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def solve(A): if all(a == -1 for a in A): print(0, 0) return minval, maxval = float("inf"), float("-inf") m = float("-inf") for a, b in zip(A, A[1:]): if a == -1 and b >= 0: minval, maxval = min(minval, b), max(maxval, b) elif b == -1 and a >= 0: minval, maxval = min(minval, a), max(maxval, a) elif a >= 0 and b >= 0: m = max(m, abs(a - b)) k = (minval + maxval) // 2 m = max(m, maxval - k) print(m, k) def main(): t = int(input().strip()) for _ in range(t): n = int(input().strip()) A = [int(s) for s in input().strip().split()] solve(A) main()
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER RETURN ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for ti in range(t): n = int(input()) a = input().split() for i in range(n): a[i] = int(a[i]) m = 0 thenos = set() if a[0] == -1 and a[1] != -1: thenos.add(a[1]) for i in range(1, n): if a[i] != -1 and a[i - 1] != -1: k = abs(a[i] - a[i - 1]) if k > m: m = k if a[i] == -1: if a[i - 1] != -1: thenos.add(a[i - 1]) if i < n - 1 and a[i + 1] != -1: thenos.add(a[i + 1]) thenos = list(thenos) if len(thenos) != 0: maxno = max(thenos) minno = min(thenos) k = int((maxno + minno) / 2) maxhere = maxno - k if maxhere > m: print(maxhere, k) else: print(m, k) else: print("0 1")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = [a[0]] for j in range(1, n): if a[j] != -1: b.append(a[j]) elif b[len(b) - 1] != -1: b.append(-1) if len(b) == 1: print(0, 0) continue mini = 10**9 + 1 maxi = -2 for j in range(len(b) - 1): if b[j] == -1: if b[j + 1] > maxi: maxi = b[j + 1] if b[j + 1] < mini: mini = b[j + 1] elif b[j + 1] == -1: if b[j] > maxi: maxi = b[j] if b[j] < mini: mini = b[j] k = (maxi + mini) // 2 m = -2 for j in range(len(b) - 1): if b[j] == -1: b[j] = k if b[j + 1] == -1: b[j + 1] = k if abs(b[j + 1] - b[j]) > m: m = abs(b[j + 1] - b[j]) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) mn = 10000000000 mx = -1 inp = [int(i) for i in input().split()] for i in range(n): if inp[i] != -1: if i > 0 and inp[i - 1] == -1: mn = min(mn, inp[i]) mx = max(mx, inp[i]) if i < n - 1 and inp[i + 1] == -1: mn = min(mn, inp[i]) mx = max(mx, inp[i]) if mx == -1: k = 0 else: k = (mx + mn) // 2 ans = 0 if inp[0] == -1: inp[0] = k for i in range(1, n): if inp[i] == -1: inp[i] = k ans = max(ans, abs(inp[i] - inp[i - 1])) print(ans, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for tc in range(int(input())): n = int(input()) l = list(map(int, input().split())) if l.count(-1) == n: print(0, 1) continue mi = 10**9 + 7 ma = -100 for i in range(n - 1): if l[i] == -1: if l[i + 1] != -1: if mi > l[i + 1]: mi = l[i + 1] if ma < l[i + 1]: ma = l[i + 1] elif l[i + 1] == -1: if mi > l[i]: mi = l[i] if ma < l[i]: ma = l[i] di = (ma + mi) // 2 for i in range(n): if l[i] == -1: l[i] = di ans = -100 for i in range(n - 1): if abs(l[i] - l[i + 1]) > ans: ans = abs(l[i] - l[i + 1]) print(ans, di)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) a = [int(x) for x in input().split()] d = set() for i, x in enumerate(a): if x == -1: if i > 0: d.add(a[i - 1]) if i < len(a) - 1: d.add(a[i + 1]) d = [x for x in list(d) if x != -1] a2 = (min(d) + max(d)) // 2 if d else 0 a = [(x if x != -1 else a2) for x in a] print( "%d %d" % ( max( [ abs(a[x] - a[x + 1]) for x in range(len(a) - 1) if a[x] != -1 and a[x + 1] != -1 ] ), a2, ) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys input = lambda: sys.stdin.readline().rstrip() def dp_(mi): dp = [0] for i in range(len(mi) - 1): dp.append(abs(mi[i] - mi[i + 1])) return dp def main(): for _ in range(int(input())): l = int(input()) mas = list(map(int, input().split())) c = [] an = [] for i in range(l): if mas[i] == -1: an.append(i) if i == 0: if mas[i + 1] != -1: c.append(mas[i + 1]) elif i == l - 1: if mas[i - 1] != -1: c.append(mas[i - 1]) else: if mas[i - 1] != -1: c.append(mas[i - 1]) if mas[i + 1] != -1: c.append(mas[i + 1]) g = 0 if len(c) != 0: ans = (max(c) + min(c)) // 2 for i in an: mas[i] = ans print(max(dp_(mas)), ans) else: print(0, 1) main()
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
I = input for _ in [0] * int(I()): n = int(I()) a = (*map(int, I().split()),) b = [i for i, x in enumerate(a) if x < 0] l = 0 r = [] for i, j in zip([-1] + b, b + [n]): if j > i + 1: d = a[i + 1 : j] l = max(l, l, *(abs(x - y) for x, y in zip(d, d[1:]))) r += ([], [a[i + 1]])[i >= 0] + ([], [a[j - 1]])[j < n] r = r or [0] m = min(r) z = (max(r) - m + 1) // 2 print(max(z, l), m + z)
ASSIGN VAR VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR BIN_OP VAR LIST VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP LIST LIST VAR BIN_OP VAR NUMBER VAR NUMBER LIST LIST VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
from sys import stdin input = stdin.readline for xoxo in range(1): for _ in range(int(input())): b = [] n = int(input()) a = [0] + list(map(int, input().split())) if a.count(-1) == n: print("0 0") continue a.append(0) for i in range(1, n + 1): if a[i] != -1: if a[i - 1] == -1 or a[i + 1] == -1: b.append(a[i]) b = set(b) s = sum(b) ans1 = (max(b) + min(b)) // 2 ans = [] m1 = 0 for j in range(2): ans1 += j m1 = 0 for i in range(2, n + 1): x, y = a[i], a[i - 1] if x == -1: x = ans1 if y == -1: y = ans1 m1 = max(abs(x - y), m1) ans.append([ans1, m1]) if ans[0][1] <= ans[1][1]: print(ans[0][1], ans[0][0]) else: print(ans[1][1], ans[1][0])
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) ar = list(map(int, input().split())) br = [] for i in range(n): if ar[i] != -1: if i - 1 >= 0 and ar[i - 1] == -1: br.append(ar[i]) elif i + 1 < n and ar[i + 1] == -1: br.append(ar[i]) if br == []: print(0, 0) continue br.sort() k = (br[0] + br[-1]) // 2 m = 0 for i in range(n): if ar[i] == -1: ar[i] = k for i in range(1, n): m = max(abs(ar[i] - ar[i - 1]), m) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def calc(a, k): ret = 0 prev = -1 for i in a: if i == -1: if prev != -1: ret = max(ret, abs(k - prev)) prev = k else: if prev != -1: ret = max(ret, abs(i - prev)) prev = i return ret t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) lb, ub = 0, 10**9 while ub - lb > 2: k1 = (2 * lb + ub) // 3 k2 = (lb + 2 * ub) // 3 m1 = calc(a, k1) m2 = calc(a, k2) if m1 == m2: lb, ub = k1, k2 elif m1 < m2: ub = k2 else: lb = k1 mk = [(calc(a, k), k) for k in range(lb, ub + 1)] m, k = min(mk) print(m, k)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) if all(x == -1 for x in a): print(0, 42) continue pairs = zip(a, a[1:]) pairs_filtered = filter( lambda t: (t[0] == -1 or t[1] == -1) and t[0] != t[1], pairs ) nums = list(map(lambda t: t[0] if t[0] != -1 else t[1], pairs_filtered)) res_n = (max(nums) + min(nums)) // 2 a = list(map(lambda x: x if x != -1 else res_n, a)) diff = map(lambda x: abs(x[0] - x[1]), zip(a, a[1:])) print(max(diff), res_n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) d = {} for i in range(1, n - 1): if a[i] > -1 and (a[i + 1] == -1 or a[i - 1] == -1): d[a[i]] = 1 if a[0] > -1 and a[1] == -1: d[a[0]] = 1 if a[-1] > -1 and a[-2] == -1: d[a[-1]] = 1 diff = -1 for i in range(1, n): if a[i] > -1 and a[i - 1] > -1: diff = max(diff, abs(a[i] - a[i - 1])) def check(k, d): mi = -(10**12) ma = 10**12 for i in d: mi = max(mi, i - k, 0) ma = min(ma, i + k) if mi <= ma: return 1, mi else: return 0, 0 if len(d) == 0: print(0, 5) else: low = diff high = 10**12 while low < high: mid = (low + high) // 2 p = check(mid, d) if p[0]: ind = p[1] high = mid else: low = mid + 1 p = check(low, d) print(low, p[1])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER VAR RETURN NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) tank = [] for i in range(1, n - 1): if a[i] == -1: if a[i - 1] != -1: tank.append(a[i - 1]) if a[i + 1] != -1: tank.append(a[i + 1]) if a[0] == -1 and a[1] != -1: tank.append(a[1]) if a[n - 1] == -1 and a[n - 2] != -1: tank.append(a[n - 2]) tank.sort() if len(tank) == 1: k = tank[0] elif len(tank) == 0: k = 0 else: k = (tank[-1] + tank[0]) // 2 ma = 0 for i in range(n): if a[i] == -1: a[i] = k if i == 0: continue ma = max(ma, abs(a[i] - a[i - 1])) print(ma, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = [] b = [] l = list(map(int, input().split())) if l.count(-1) == n: print(0, 0) else: for i in range(n): if l[i] != -1: if i == 0: if l[i + 1] == -1: a.append(l[i]) elif i == n - 1: if l[i - 1] == -1: a.append(l[i]) elif l[i + 1] == -1 or l[i - 1] == -1: a.append(l[i]) k = (max(a) + min(a)) // 2 for i in range(n): if l[i] == -1: l[i] = k for i in range(1, n): b.append(abs(l[i] - l[i - 1])) print(max(b), k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def want(num): L = 0 R = 10**9 for i in range(n - 1): if a[i] != -1 and a[i + 1] != -1: if abs(a[i] - a[i + 1]) > num: return -1 elif a[i] == -1 and a[i + 1] != -1: L = max(L, a[i + 1] - num) R = min(R, a[i + 1] + num) if L > a[i + 1] + num or R < a[i + 1] - num: return -1 elif a[i] != -1 and a[i + 1] == -1: L = max(L, a[i] - num) R = min(R, a[i] + num) if L > a[i] + num or R < a[i] - num: return -1 if L > R: return -1 return L t = int(input()) nans = 0 for loop in range(t): n = int(input()) a = list(map(int, input().split())) l = -1 r = 10**9 while r - l != 1: m = (r + l) // 2 ret = want(m) if ret < 0: l = m else: r = m nans = ret print(r, nans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) arr = [] diff = [] for i in range(n): if i == 0: if l[i] >= 0 and l[i + 1] == -1: arr.append(l[i]) elif i == n - 1: if l[i] >= 0 and l[i - 1] == -1: arr.append(l[i]) elif l[i] >= 0 and (l[i - 1] == -1 or l[i + 1] == -1): arr.append(l[i]) if i < n - 1: if l[i] >= 0 and l[i + 1] >= 0: diff.append(abs(l[i] - l[i + 1])) arr.sort() if arr == []: print(0, 0) else: if diff == []: diff.append(0) if (arr[-1] - arr[0]) % 2 == 0: q = (arr[-1] - arr[0]) // 2 else: q = (arr[-1] - arr[0]) // 2 + 1 s = max(diff) print(max(s, q), (arr[-1] + arr[0]) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR LIST EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) cnt = 1 if a[0] != -1 and a[1] == -1 else 0 maxdif = 0 max_ai = a[0] if a[0] != -1 and a[1] == -1 else 0 min_ai = a[0] if a[0] != -1 and a[1] == -1 else 10**9 for i in range(1, n - 1): if a[i - 1] != -1 and a[i] != -1: maxdif = max(maxdif, abs(a[i] - a[i - 1])) if a[i] != -1 and (a[i - 1] == -1 or a[i + 1] == -1): min_ai = min(min_ai, a[i]) max_ai = max(max_ai, a[i]) cnt += 1 if a[n - 2] != -1 and a[n - 1] != -1: maxdif = max(maxdif, abs(a[n - 1] - a[n - 2])) if a[n - 1] != -1 and a[n - 2] == -1: min_ai = min(min_ai, a[n - 1]) max_ai = max(max_ai, a[n - 1]) cnt += 1 if cnt != 0: avg = (max_ai + min_ai) // 2 print(max(max_ai - avg, maxdif), avg) else: print(0, 0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
num_cases = int(input()) for case in range(num_cases): n = int(input()) min_num = 1000000027 max_num = 0 biggest = 0 nums = input().split() for i in range(len(nums)): nums[i] = int(nums[i]) for i in range(len(nums)): curr_num = nums[i] prev_num = nums[i - 1] if curr_num == -1: if i != 0: if prev_num != -1: max_num = max(max_num, prev_num) min_num = min(min_num, prev_num) if i != len(nums) - 1: next_num = nums[i + 1] if next_num != -1: max_num = max(max_num, next_num) min_num = min(min_num, next_num) elif i != 0 and prev_num != -1: biggest = max(biggest, abs(curr_num - prev_num)) if min_num > max_num: ans = max_num else: ans = (min_num + max_num) // 2 print(max(biggest, max(ans - min_num, max_num - ans)), end=" ") print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
v = int(input()) for l in range(v): min_ = 10**9 max_ = 0 _ = input() s = [int(x) for x in input().split(" ")] for i, p in enumerate(s): if p == -1: if i - 1 >= 0: if s[i - 1] != -1: min_ = min([min_, s[i - 1]]) max_ = max([max_, s[i - 1]]) if i + 1 < len(s): if s[i + 1] != -1: min_ = min([min_, s[i + 1]]) max_ = max([max_, s[i + 1]]) k = (min_ + max_) // 2 s = [(x if x != -1 else k) for x in s] max_2 = 0 for i, a in enumerate(s): if i - 1 >= 0: max_2 = max([max_2, abs(a - s[i - 1])]) print(max_2, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
from sys import stdin, stdout input = stdin.buffer.readline t = int(input()) def main(): n = int(input()) arr = list(map(int, input().split())) diff = maxval = 0 minval = 10**9 allneg = True for i in range(n): if arr[i] >= 0: allneg = False if arr[i] == -1: if i > 0 and arr[i - 1] >= 0: maxval = max(maxval, arr[i - 1]) minval = min(minval, arr[i - 1]) if i < n - 1 and arr[i + 1] >= 0: maxval = max(maxval, arr[i + 1]) minval = min(minval, arr[i + 1]) if i < n - 1 and arr[i] >= 0 and arr[i + 1] >= 0: diff = max(diff, abs(arr[i] - arr[i + 1])) if allneg: return 0, 0 avg = (maxval + minval) // 2 return max(diff, abs(maxval - avg), abs(minval - avg)), avg for _ in range(t): m, k = main() print(m, k)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR RETURN NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for t in range(int(input())): n = int(input()) l = list(map(int, input().split())) temp = [] if l[0] != -1 and l[1] == -1: temp.append(l[0]) for i in range(1, n - 1): if l[i] != -1 and (l[i - 1] == -1 or l[i + 1] == -1): temp.append(l[i]) if l[n - 1] != -1 and l[n - 2] == -1: temp.append(l[n - 1]) if len(temp) == 0: print(0, 0) continue mi = min(temp) ma = max(temp) no = (ma + mi) // 2 dif = 0 for i in range(n - 1): if l[i] == -1: l[i] = no if l[i + 1] == -1: l[i + 1] = no if abs(l[i] - l[i + 1]) > dif: dif = abs(l[i] - l[i + 1]) print(dif, no)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) lis = list(map(int, input().split())) maxi = 0 tempLis = [] for j in range(0, n - 1): if lis[j] != -1 and lis[j + 1] != -1: if abs(lis[j] - lis[j + 1]) > maxi: maxi = abs(lis[j] - lis[j + 1]) elif lis[j] == -1 and lis[j + 1] != -1: tempLis.append(lis[j + 1]) elif lis[j] != -1 and lis[j + 1] == -1: tempLis.append(lis[j]) if len(tempLis) == 0: print(0, end=" ") print(0) continue tempMax = max(tempLis) tempMin = min(tempLis) k = int((tempMax + tempMin) / 2) m = max(maxi, abs(tempMax - k), abs(tempMin - k)) print(m, end=" ") print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) l = [int(x) for x in input().split()] m1, m2 = -1, 10**9 + 1 for x in l: if x == -1: continue if x > m1: m1 = x if x < m2: m2 = x if m1 == -1 and m2 == 10**9 + 1: print(0, 0) continue m3, m4 = -1, 10**9 + 1 now = 0 for x in range(1, n): if l[x - 1] == l[x] == -1: continue if l[x - 1] != -1 and l[x] != -1: continue if l[x - 1] == -1: now = l[x] else: now = l[x - 1] if m3 < now: m3 = now if m4 > now: m4 = now k = (m3 + m4) // 2 num = 0 for x in range(n): if l[x] == -1: l[x] = k for x in range(1, n): now = abs(l[x] - l[x - 1]) if now > num: num = now print(num, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) maxi = -sys.maxsize mini = sys.maxsize m = 0 for i in range(1, n): if a[i] != -1 and a[i - 1] != -1: m = max(m, abs(a[i] - a[i - 1])) for i in range(n): if a[i] != -1: if i - 1 >= 0 and a[i - 1] == -1: mini = min(mini, a[i]) maxi = max(maxi, a[i]) if i + 1 < n and a[i + 1] == -1: mini = min(mini, a[i]) maxi = max(maxi, a[i]) k = (mini + maxi + 1) // 2 print(max(m, maxi - k, k - mini), k)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def solve(): n = int(input()) a = list(map(int, input().split())) b = [] ans = 0 for i in range(n): if i: if a[i] != -1 and a[i - 1] != -1: ans = max(abs(a[i] - a[i - 1]), ans) if a[i] == -1: if i and a[i - 1] != -1: b.append(a[i - 1]) if i != n - 1 and a[i + 1] != -1: b.append(a[i + 1]) if not b: return print(0, 1) ma = max(b) mi = min(b) s = (ma + mi) // 2 print(max(ma - s, s - mi, ans), s) for i in range(int(input())): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) k = 0 m = -1 p = 10**9 + 7 for i in range(n): if l[i] == -1: t = str(int(l[max(0, i - 1)] != -1)) + str(int(l[min(i + 1, n - 1)] != -1)) if t == "11": m = max([m, l[i - 1], l[i + 1]]) p = min([p, l[i - 1], l[i + 1]]) elif t == "01": m = max(m, l[i + 1]) p = min(p, l[i + 1]) elif t == "10": m = max(m, l[i - 1]) p = min(p, l[i - 1]) k = (m + p) // 2 m = 0 for i in range(n - 1): if l[i] == -1: l[i] = k if l[i + 1] == -1: l[i + 1] = k if abs(l[i + 1] - l[i]) > m: m = abs(l[i + 1] - l[i]) print(m, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def calc(u): global n, a ans = 0 for i in range(n - 1): x = a[i] y = a[i + 1] if x == -1: x = u if y == -1: y = u ans = max(ans, abs(x - y)) return ans def check(u): return calc(u + 1) - calc(u) def solve(): global n, a n = int(input()) a = list(map(int, input().split())) l, r = 0, 10**9 + 1 if check(l) >= 0: print(calc(0), 0) return while r - l > 1: mid = (l + r) // 2 if check(l) * check(mid) > 0: l = mid else: r = mid print(*min((calc(i), i) for i in range(max(0, l - 2), min(10**9, l + 2)))) t = int(input()) for _ in range(t): solve()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER RETURN WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) aq = [int(v) for v in sys.stdin.readline().split()] ma = -1 mi = 2000000000 f = False for i, a in enumerate(aq): f |= a != -1 if i == 0: continue pa = aq[i - 1] if a == -1 and pa != -1: ma = max(ma, pa) mi = min(mi, pa) elif a != -1 and pa == -1: ma = max(ma, a) mi = min(mi, a) k = (ma + mi) // 2 if not f: print("0 0") continue mm = -1 la = aq[0] if la == -1: la = k for a in aq[1:]: if a == -1: a = k mm = max(mm, abs(a - la)) la = a print("%s %s" % (mm, k))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for case in range(1, t + 1): n = int(input()) a = [int(x) for x in input().split()] assert len(a) == n caps = [] for i, x in enumerate(a): if x == -1: if i > 0 and a[i - 1] != -1: caps.append(a[i - 1]) if i < n - 1 and a[i + 1] != -1: caps.append(a[i + 1]) if caps: k = round((max(caps) + min(caps)) / 2) else: k = 42 a_complete = [(x if x != -1 else k) for x in a] m = max(abs(a_complete[i] - a_complete[i - 1]) for i in range(1, n)) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for t in range(int(input())): n = int(input()) a = map(int, input().split()) a = list(a) start = -1 flag = False elems = [] for i in range(1, n - 1): if a[i] != -1 and (a[i - 1] == -1 or a[i + 1] == -1): elems.append(a[i]) if len(a) > 0 and a[1] == -1 and a[0] != -1: elems.append(a[0]) if len(a) > 1 and a[-2] == -1 and a[-1] != -1: elems.append(a[-1]) if len(elems) == 0: if max(a) == -1: print("0 0") else: print("0", max(a)) continue k = (max(elems) + min(elems)) // 2 maxd = 0 for i in range(n - 1): if a[i] + a[i + 1] == -2: diff = 0 elif a[i] == -1: diff = abs(k - a[i + 1]) elif a[i + 1] == -1: diff = abs(k - a[i]) else: diff = abs(a[i] - a[i + 1]) maxd = max(maxd, diff) print(maxd, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for kek in range(t): n = int(input()) a = list(map(int, input().split())) mi = 10**9 ma = 0 sosed = set() k = 777 for i in range(n): if a[i] == -1: if i + 1 < n: if a[i + 1] != -1: sosed.add(a[i + 1]) if i - 1 >= 0: if a[i - 1] != -1: sosed.add(a[i - 1]) if len(sosed) != 0: k = (min(sosed) + max(sosed)) // 2 if k == -1: k = 777 for i in range(n): if a[i] == -1: a[i] = k ans = 0 for i in range(1, n): ans = max(ans, abs(a[i] - a[i - 1])) print(ans, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
T = int(input()) for t in range(T): n = int(input()) A = [int(i) for i in input().split()] tmp = [] if A[0] == -1 and A[1] != -1: tmp.append(A[1]) for i in range(1, n - 1): if A[i] == -1: if A[i + 1] != -1: tmp.append(A[i + 1]) if A[i - 1] != -1: tmp.append(A[i - 1]) if A[-1] == -1 and A[-2] != -1: tmp.append(A[-2]) if len(tmp) == 0: k = 0 else: tmp = set(tmp) k = (min(tmp) + max(tmp)) // 2 m = 0 B = [(A[i] if A[i] >= 0 else k) for i in range(n)] for i in range(1, n): m = max(abs(B[i] - B[i - 1]), m) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys t = int(sys.stdin.readline().rstrip()) def main(): for _ in range(t): n = int(sys.stdin.readline().rstrip()) (*a,) = map(int, sys.stdin.readline().split()) m = 0 res = set() for i in range(n): cur = a[i] if cur == -1: if i > 0 and a[i - 1] != -1: res.add(a[i - 1]) if i < n - 1 and a[i + 1] != -1: res.add(a[i + 1]) elif i > 0 and a[i - 1] != -1: m = max(m, abs(cur - a[i - 1])) res = sorted(res) if not res: k = 0 else: k = (res[0] + res[-1]) // 2 m = max(res[-1] - k, m) yield m, k ans = main() for a in ans: print(*a, sep=" ")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def program(): n = int(input()) l = list(map(int, input().split())) l2 = [] l3 = [] for i in range(n): if l[i] == -1: if i == 0: nex = l[1] prev = -1 elif i == n - 1: nex = -1 prev = l[n - 2] else: nex = l[i + 1] prev = l[i - 1] if nex != -1: l2.append(nex) if prev != -1: l2.append(prev) else: if i == 0: nex = l[1] prev = -1 elif i == n - 1: nex = -1 prev = l[n - 2] else: nex = l[i + 1] prev = l[i - 1] if nex != -1: l3.append(abs(l[i] - nex)) if prev != -1: l3.append(abs(l[i] - prev)) if len(l2) == 0: print("0 0") return 0 l2 = set(l2) k = (max(l2) + min(l2)) // 2 if len(l3) == 0: m = max(l2) - k else: m = max(max(l3), max(l2) - k) print(m, k) t = int(input()) for i in range(t): program()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for j in range(t): n = int(input()) a = [int(x) for x in input().split()] d_r = [] d_x = [] for i in range(1, len(a)): if a[i] != -1 and a[i - 1] != -1: d_r.append(abs(a[i] - a[i - 1])) elif a[i] == -1 and a[i - 1] != -1: d_x.append(a[i - 1]) elif a[i] != -1 and a[i - 1] == -1: d_x.append(a[i]) if len(d_r) == 0: Max = 0 else: Max = max(d_r) if len(d_x) == 0: xMax, xMin = 0, 0 else: xMax, xMin = max(d_x), min(d_x) k = (xMin + xMax) // 2 m = xMax - k if xMax - k > Max else Max print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def cmax(a, b): if a > b: return a else: return b def cmin(a, b): if a > b: return b else: return a t = int(input()) for tt in range(t): n = int(input()) L, R = int(1000000000), int(0) ans, cnt = 0, 0 a = [int(x) for x in input().split()] for i in range(n): if i > 0 and a[i] != -1 and a[i - 1] != -1: ans = cmax(ans, abs(a[i] - a[i - 1])) if a[i] != -1: continue cnt = cnt + 1 if i > 0 and a[i - 1] != -1: L = cmin(L, a[i - 1]) R = cmax(R, a[i - 1]) if i != n - 1 and a[i + 1] != -1: L = cmin(L, a[i + 1]) R = cmax(R, a[i + 1]) if cnt == n: ans = L = R = 0 ans = cmax(ans, (R - L + 1) // 2) print(ans, (L + R) // 2)
FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) minn = 10**9 maxx = 0 t = 0 for i in range(n - 1): if a[i] != -1 and a[i + 1] == -1: minn = min(a[i], minn) maxx = max(a[i], maxx) elif a[i] == -1 and a[i + 1] != -1: minn = min(a[i + 1], minn) maxx = max(a[i + 1], maxx) elif a[i] != -1 and a[i + 1] != -1: t = max(t, abs(a[i] - a[i + 1])) if minn == 10**9: minn = 0 mm = float("inf") kk = -1 k = (maxx + minn) // 2 m = max(abs(maxx - k), abs(minn - k), t) if m < mm: mm = m kk = k print(mm, kk)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
n = int(input()) for i in range(n): t = int(input()) l = input().split() for j in range(t): l[j] = int(l[j]) maxx = -1 minn = 1000000000 for j in range(t): if j != 0 and j != t - 1: if l[j] != -1 and (l[j - 1] == -1 or l[j + 1] == -1): if l[j] < minn: minn = l[j] if l[j] > maxx: maxx = l[j] elif j == 0: if l[j] != -1 and l[j + 1] == -1: if l[j] < minn: minn = l[j] if l[j] > maxx: maxx = l[j] elif l[j] != -1 and l[j - 1] == -1: if l[j] < minn: minn = l[j] if l[j] > maxx: maxx = l[j] k = int((maxx + minn) / 2) maxx = 0 for j in range(t - 1): if l[j] == -1: l[j] = k if l[j + 1] == -1: l[j + 1] = k if abs(l[j] - l[j + 1]) > maxx: maxx = abs(l[j] - l[j + 1]) print(maxx, end=" ") print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) s = "-2 " + input() + " -2" l = [int(x) for x in s.split()] l1 = [] max_abs = 0 for i in range(1, n + 1): if l[i] > -1: if l[i - 1] == -1 or l[i + 1] == -1: l1.append(l[i]) if l[i + 1] > -1: max_abs = max(max_abs, abs(l[i + 1] - l[i])) if len(l1) == 0: l1.append(0) ma = max(l1) mi = min(l1) ans = (ma + mi) // 2 print(max(ma - ans, max_abs), ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys input = sys.stdin.readline for _ in range(int(input().strip())): n = int(input().strip()) arr = list(map(int, input().strip().split())) ne = [] for i in range(n): if i == 0: if arr[i] == -1 and arr[i + 1] != -1: ne.append(arr[i + 1]) elif i == n - 1: if arr[i] == -1 and arr[i - 1] != -1: ne.append(arr[i - 1]) elif arr[i] == -1: if arr[i - 1] != -1: ne.append(arr[i - 1]) if arr[i + 1] != -1: ne.append(arr[i + 1]) ne.sort() mi, ma = 0, 0 if len(ne) == 1: mi, ma = ne[0], ne[0] elif len(ne) > 1: mi, ma = ne[0], ne[-1] k = (ma + mi) // 2 ans = ma - k for i in range(n): if arr[i] == -1: arr[i] = k for i in range(n - 1): ans = max(ans, abs(arr[i] - arr[i + 1])) print(ans, k)
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def calc(val, lista): mx = 0 for i in range(1, len(lista)): x, y = lista[i], lista[i - 1] if x == -1: x = val if y == -1: y = val mx = max(mx, abs(x - y)) return mx for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] l, ret, h, m = 0, 0, 10000000000, 10000000000 while l < h: mid = (l + (h - 1)) // 2 mx1 = calc(mid, a) mx2 = calc(mid + 1, a) if mx1 <= mx2: m = mx1 h = mid else: m = mx2 ret = mid + 1 l = mid + 1 if m == 10000000000: m = 0 print(m, ret)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def tc(): n = int(input()) a = list(map(int, input().split())) m = 0 minx = float("inf") maxx = 0 for i in range(1, n): if a[i] == -1 and a[i - 1] == -1: continue elif a[i] != -1 and a[i - 1] != -1: m = max(abs(a[i] - a[i - 1]), m) else: x = a[i] if a[i - 1] == -1 else a[i - 1] minx = min(x, minx) maxx = max(x, maxx) k = (minx + maxx) // 2 if k != k: k = 1 m = max(m, maxx - k, k - minx) print(m, k) T = int(input()) for _ in range(T): tc()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] b = [] c = 0 for i in range(len(a) - 1): if a[i] == -1 and a[i + 1] != -1: b.append(a[i + 1]) elif a[i + 1] == -1 and a[i] != -1: b.append(a[i]) elif a[i] != -1 and a[i + 1] != -1: c = max(c, abs(a[i] - a[i + 1])) b.sort() if len(b) != 0: ans = (b[0] + b[-1]) // 2 mx = max(abs(b[-1] - ans), abs(b[0] - ans), c) print(mx, ans) else: print(0, 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def check(l, x): ans = 0 for i in l: ans = max(ans, abs(i - x)) return ans for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) minc = a.count(-1) if minc == n: print(0, 0) else: l = [] for i in range(n): if i == 0: if a[i] != -1 and a[i + 1] == -1: l.append(a[i]) elif i == n - 1: if a[i] != -1 and a[i - 1] == -1: l.append(a[i]) elif a[i] != -1: if a[i + 1] == -1: l.append(a[i]) if a[i - 1] == -1: l.append(a[i]) l = list(set(l)) l = sorted(l) ans = 0 low = 0 high = 10**10 while low <= high: mid = (low + high) // 2 cm = check(l, mid) cl = check(l, mid - 1) cr = check(l, mid + 1) if cm <= cl and cm <= cr: ans = mid break elif cm <= cl and cm >= cr: low = mid + 1 else: high = mid - 1 b = [] for i in a: if i != -1: b.append(i) else: b.append(ans) val = 0 for i in range(1, n): val = max(val, abs(b[i] - b[i - 1])) print(val, ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for test in range(t): n = int(input()) a = [int(x) for x in input().split()] mm = 0 x = [] for i in range(n): if a[i] == -1: if i + 1 < n and a[i + 1] != -1: x.append(a[i + 1]) if i - 1 >= 0 and a[i - 1] != -1: x.append(a[i - 1]) elif i + 1 < n and a[i + 1] != -1 and abs(a[i] - a[i + 1]) > mm: mm = abs(a[i] - a[i + 1]) if len(x) == 0: print(mm, 0) continue ss = min(x) ll = max(x) k = (ss + ll) // 2 for i in range(n): if a[i] == -1: a[i] = k for i in range(n): if i + 1 < n and abs(a[i] - a[i + 1]) > mm: mm = abs(a[i] - a[i + 1]) print(mm, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys input = sys.stdin.buffer.readline def print(*vals): sys.stdout.write(" ".join(map(str, vals)) + "\n") def prog(): for _ in range(int(input())): n = int(input()) integers = list(map(int, input().split())) max_diff = 0 smallest = 10**9 largest = 0 for i in range(n - 1): if integers[i] == -1 and integers[i + 1] != -1: smallest = min(smallest, integers[i + 1]) largest = max(largest, integers[i + 1]) elif integers[i + 1] == -1 and integers[i] != -1: largest = max(largest, integers[i]) smallest = min(smallest, integers[i]) else: max_diff = max(max_diff, abs(integers[i] - integers[i + 1])) best_k_diff = (largest - smallest + 1) // 2 best_k = (largest + smallest) // 2 if max_diff > best_k_diff: print(max_diff, best_k) else: print(best_k_diff, best_k) prog()
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = [0] + a + [0] final = [ b[i] for i in range(1, len(b) - 1) if b[i] != -1 and (b[i - 1] == -1 or b[i + 1] == -1) ] final.sort() ans = 0 if len(final) == 0: print(0, 1) else: mid = len(final) // 2 mid = (final[0] + final[-1] + 1) // 2 for i in range(0, len(a)): if a[i] == -1: a[i] = mid k = mid x = 0 for i in range(0, len(a) - 1): x = max(x, abs(a[i] - a[i + 1])) print(x, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) min_value = max(a) + 1 max_value = min(a) - 1 check = False for j in range(n): if a[j] != -1 and (j > 0 and a[j - 1] == -1 or j < n - 1 and a[j + 1] == -1): min_value = min(min_value, a[j]) max_value = max(max_value, a[j]) check = True if check == False: k = 0 else: k = round((min_value + max_value) / 2) for j in range(len(a)): if a[j] == -1: a[j] = k m = 0 for j in range(1, len(a)): m = max(m, abs(a[j] - a[j - 1])) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): a = int(input()) h = list(map(int, input().split())) mi = 1000000000.0 + 1 ma = 0 ans = 0 f = 0 if a > 2: for i in range(1, a - 1): if h[i - 1] == -1 and h[i] != -1: mi = min(h[i], mi) ma = max(h[i], ma) f = 1 elif h[i - 1] != -1 and h[i] == -1: mi = min(h[i - 1], mi) ma = max(h[i - 1], ma) f = 1 else: ans = max(ans, abs(h[i - 1] - h[i])) if h[i + 1] == -1 and h[i] != -1: mi = min(h[i], mi) ma = max(h[i], ma) f = 1 elif h[i + 1] != -1 and h[i] == -1: mi = min(h[i + 1], mi) ma = max(h[i + 1], ma) f = 1 else: ans = max(ans, abs(h[i + 1] - h[i])) elif h[0] == -1 and h[1] != -1: mi = min(h[1], mi) ma = max(h[1], ma) f = 1 elif h[0] != -1 and h[1] == -1: mi = min(h[0], mi) ma = max(h[0], ma) f = 1 else: ans = max(ans, abs(h[0] - h[1])) if f == 1: print(max(ans, ma - (ma + mi) // 2), (ma + mi) // 2) else: print(0, 0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
test = int(input()) for i in range(0, test): a = input() arr = list(map(int, input().split())) brr = [] for i in range(1, len(arr) - 1): if arr[i] == -1: brr.append(arr[i - 1]) brr.append(arr[i + 1]) if len(arr) > 1 and arr[0] == -1: brr.append(arr[1]) if len(arr) > 1 and arr[len(arr) - 1] == -1: brr.append(arr[len(arr) - 2]) s = set(brr) brr = [] for i in s: if not i == -1: brr.append(i) if len(brr) == 0: brr.append(42) ans = (max(brr) + min(brr)) // 2 crr = [] for i in arr: if i == -1: crr.append(ans) else: crr.append(i) maxx = -1 for i in range(0, len(arr) - 1): if abs(crr[i] - crr[i + 1]) > maxx: maxx = abs(crr[i] - crr[i + 1]) print(maxx, ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) x = list(map(int, input().split())) a = [] vis = [0] * n for i in range(n): if x[i] == -1: if i - 1 >= 0 and vis[i - 1] == 0 and x[i - 1] != -1: a += [x[i - 1]] vis[i - 1] = 1 if i + 1 < n and vis[i + 1] == 0 and x[i + 1] != -1: a += [x[i + 1]] vis[i + 1] = 1 if len(a) == 0: print(0, 1) else: a.sort() k = (a[0] + a[-1]) // 2 for i in range(n): if x[i] == -1: x[i] = k m = max([abs(x[i + 1] - x[i]) for i in range(n - 1)]) print(m, k)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for t in range(int(input())): n = int(input()) arr = list(map(int, input().split())) prev = -1 k = -1 diff = -1 minimum = 9999999999999999999999 maximum = -1 for i in range(n): if arr[i] == -1: if i != 0 and arr[i - 1] != -1: minimum = min(minimum, arr[i - 1]) maximum = max(maximum, arr[i - 1]) if i != n - 1 and arr[i + 1] != -1: minimum = min(minimum, arr[i + 1]) maximum = max(maximum, arr[i + 1]) if maximum == -1: print(0, 0) else: k1 = minimum + (maximum - minimum) // 2 diff1 = -1 if arr[0] == -1: arr[0] = k1 for i in range(1, n): if arr[i] == -1: arr[i] = k1 diff1 = max(diff1, abs(arr[i] - arr[i - 1])) print(diff1, k1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) mn = 10**9 + 1 mx = -1 realmx = 0 realmn = 0 for i in range(n): if arr[i] < 0: if i > 0 and arr[i - 1] != -1: mx = max(arr[i - 1], mx) mn = min(arr[i - 1], mn) if i < n - 1 and arr[i + 1] != -1: mx = max(arr[i + 1], mx) mn = min(arr[i + 1], mn) elif i > 0 and arr[i - 1] != -1: realmx = max(realmx, abs(arr[i] - arr[i - 1])) realmm = min(realmx, abs(arr[i] - arr[i - 1])) ans = (mx + mn) // 2 dist_ans = mx - ans if dist_ans >= realmx: print(dist_ans, ans) else: print(realmx - realmn, ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(0, t): n = int(input()) a = list(map(int, input().split())) b = [] d = 0 for j in range(0, n): if j != 0: if a[j - 1] != -1 and a[j] != -1: d = max(d, abs(a[j - 1] - a[j])) if a[j] == -1: if j != 0: if a[j - 1] != -1: b.append(a[j - 1]) if j != n - 1: if a[j + 1] != -1: b.append(a[j + 1]) if len(b) == 0: print(d, 1) else: mi = min(b) ma = max(b) if (ma - mi) % 2 == 0: print(max(d, (ma - mi) // 2), (ma + mi) // 2) else: print(max(d, (ma - mi) // 2 + 1), (ma + mi) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
n = int(input()) for _ in range(n): input() nums = list(map(int, input().split())) minn, maxx = 10000000000, 0 for i in range(len(nums)): if i == 0: if nums[i] != -1 and nums[i + 1] == -1: minn = min(minn, nums[i]) maxx = max(maxx, nums[i]) elif i == len(nums) - 1: if nums[i] != -1 and nums[i - 1] == -1: minn = min(minn, nums[i]) maxx = max(maxx, nums[i]) elif nums[i] != -1 and (nums[i + 1] == -1 or nums[i - 1] == -1): minn = min(minn, nums[i]) maxx = max(maxx, nums[i]) if minn == 10000000000: print(0, end=" ") print(1) continue rep = (minn + maxx) // 2 res = 0 for i in range(len(nums)): if nums[i] == -1: nums[i] = rep if i: res = max(res, abs(nums[i] - nums[i - 1])) print(res, end=" ") print(rep)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
import sys for _ in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) max1 = 0 b = [] for i in range(n - 1): if a[i] == -1 and a[i + 1] != -1: b.append(a[i + 1]) continue if a[i] != -1 and a[i + 1] == -1: b.append(a[i]) continue if abs(a[i] - a[i + 1]) > max1: max1 = abs(a[i] - a[i + 1]) if b == []: print(max1, 0) continue max2 = (max(b) - min(b) + 1) // 2 k = (max(b) + min(b)) // 2 print(max(max1, max2), k)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def ceil(a): if a // 1 == a: return int(a) else: return int(a) + 1 for _ in range(0, int(input())): n = int(input()) a = list(map(int, input().split())) l = len(a) m = 0 li = [] for i in range(0, l - 1): if a[i] != -1 and a[i + 1] == -1: li.append(a[i]) if a[i + 1] != -1 and a[i] == -1: li.append(a[i + 1]) if a[i + 1] != -1 and a[i] != -1: if abs(a[i + 1] - a[i]) > m: m = abs(a[i + 1] - a[i]) li.sort() if len(li) == 0: print(0, 0) else: k = (+li[0] + li[-1]) // 2 m = max(abs(k - li[0]), abs(k - li[-1]), m) print(m, k)
FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
def calc(A): min_, max_ = float("Inf"), 0 found = False for i, a in enumerate(A): if a != -1: continue if 0 <= i - 1 and A[i - 1] != -1: found = True min_ = min(min_, A[i - 1]) max_ = max(max_, A[i - 1]) if i + 1 < len(A) and A[i + 1] != -1: found = True min_ = min(min_, A[i + 1]) max_ = max(max_, A[i + 1]) k = (min_ + max_) // 2 if found else 0 res = 0 for i in range(len(A)): if A[i] == -1: A[i] = k if i > 0: res = max(res, abs(A[i] - A[i - 1])) return res, k N = int(input()) cases = [] for _ in range(N): d = int(input()) cases.append(list(map(int, input().split()))) for c in cases: r = calc(c) print("{} {}".format(r[0], r[1]))
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) nei = [] default = 0 for x, y in zip(a, a[1:]): if x == -1 and y != -1: nei.append(y) if x != -1 and y == -1: nei.append(x) if x != -1 and y != -1: default = max(default, abs(x - y)) if not nei: print(0, 1) continue mi = min(nei) ma = max(nei) k = (mi + ma) // 2 m = max(abs(mi - k), abs(ma - k), default) print(m, k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
for _ in range(int(input())): n = int(input()) (*a,) = map(int, input().split()) c = a.copy() ans, ans2 = 0, 0 a.append(-1) b = [0] * n for i in range(n): if a[i] == -1: if i: if a[i - 1] + 1: b[i - 1] = 1 if n - i - 1: if a[i + 1] + 1: b[i + 1] = 1 b = [a[i] for i in range(n) if b[i]] if not b: print(0, 0) continue b, bb = (max(b) + min(b)) // 2, (max(b) + min(b) + 1) // 2 for i in range(n): if a[i] == -1: a[i] = b c[i] = bb for i in range(n - 1): ans = max(ans, abs(a[i] - a[i + 1])) for i in range(n - 1): ans2 = max(ans2, abs(c[i] - c[i + 1])) if ans > ans2: print(ans2, bb) else: print(ans, bb)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $a$ of $n$ non-negative integers. Dark created that array $1000$ 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 $k$ ($0 \leq k \leq 10^{9}$) and replaces all missing elements in the array $a$ with $k$. Let $m$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $|a_i - a_{i+1}|$ for all $1 \leq i \leq n - 1$) in the array $a$ after Dark replaces all missing elements with $k$. Dark should choose an integer $k$ so that $m$ is minimized. Can you help him? -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^{5}$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 10 ^ {9}$). If $a_i = -1$, then the $i$-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 $n$ for all test cases does not exceed $4 \cdot 10 ^ {5}$. -----Output----- Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $m$ and an integer $k$ ($0 \leq k \leq 10^{9}$) that makes the maximum absolute difference between adjacent elements in the array $a$ equal to $m$. Make sure that after replacing all the missing elements with $k$, the maximum absolute difference between adjacent elements becomes $m$. If there is more than one possible $k$, 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 -----Note----- In the first test case after replacing all missing elements with $11$ the array becomes $[11, 10, 11, 12, 11]$. The absolute difference between any adjacent elements is $1$. It is impossible to choose a value of $k$, such that the absolute difference between any adjacent element will be $\leq 0$. So, the answer is $1$. In the third test case after replacing all missing elements with $6$ the array becomes $[6, 6, 9, 6, 3, 6]$. $|a_1 - a_2| = |6 - 6| = 0$; $|a_2 - a_3| = |6 - 9| = 3$; $|a_3 - a_4| = |9 - 6| = 3$; $|a_4 - a_5| = |6 - 3| = 3$; $|a_5 - a_6| = |3 - 6| = 3$. So, the maximum difference between any adjacent elements is $3$.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) mi = 10000000000 ma = -1 md = -1 for i in range(len(a) - 1): ai, ai1 = a[i], a[i + 1] if ai == -1: if ai1 != -1: mi = min(ai1, mi) ma = max(ai1, ma) elif ai1 == -1: mi = min(ai, mi) ma = max(ai, ma) else: md = max(md, abs(ai - ai1)) if ma == -1: print(0, 1) else: mia = (mi + ma) // 2 print(max(ma - mia, mia - mi, md), mia)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy. -----Input----- The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1. -----Examples----- Input banana 4 Output 2 baan Input banana 3 Output 3 nab Input banana 2 Output -1 -----Note----- In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
def check(mid): ans = [] res = 0 for c, count in d: tmp = count // mid if count % mid != 0: tmp += 1 ans.append((c, tmp)) res += tmp return res <= n, ans a = input() n = int(input()) d = dict() t = 0 for i in a: if i not in d: d[i] = 1 t += 1 else: d[i] += 1 ans = [] res = "" for i in d: ans.append(i) res = i if n >= len(a): print(1) print(a, end="") n -= len(a) for u in range(n): print(res, end="") else: d = sorted(d.items(), key=lambda d: (d[1], d[0])) l = 1 r = len(a) res = [] count_res = 0 while l <= r: mid = (l + r) // 2 flag, tmp = check(mid) if flag: r = mid - 1 count_res = mid res = tmp else: l = mid + 1 if len(res) == 0: print(-1) else: ttt = 0 print(count_res) for c, sl in res: for j in range(sl): print(c, end="") ttt += 1 n -= ttt for i in range(n): print(a[0], end="")
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy. -----Input----- The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1. -----Examples----- Input banana 4 Output 2 baan Input banana 3 Output 3 nab Input banana 2 Output -1 -----Note----- In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
s = input() n = int(input()) d = {} for c in s: if c not in d: d[c] = 0 d[c] += 1 dcl = list(d.values()) found = False for x in range(1, 1001): if sum([((dc - 1) // x + 1) for dc in dcl]) <= n: found = True print(x) s = "".join([(key * ((d[key] - 1) // x + 1)) for key in sorted(d.keys())]) s += (n - len(s)) * "a" print(s) break if not found: print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy. -----Input----- The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1. -----Examples----- Input banana 4 Output 2 baan Input banana 3 Output 3 nab Input banana 2 Output -1 -----Note----- In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
s = input() n = int(input()) d = {} r = 0 for a in s: d.setdefault(a, 0) d[a] += 1 if d[a] > r: r = d[a] if len(d) > n: print(-1) else: l = 0 while r - l > 1: k = (l + r) // 2 cur = 0 for x in d.values(): cur += (x + k - 1) // k if cur > n: l = k else: r = k print(r) s = "" for a in d.keys(): s += a * ((d[a] + r - 1) // r) l = len(s) s += "a" * (n - len(s)) print(s)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy. -----Input----- The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1. -----Examples----- Input banana 4 Output 2 baan Input banana 3 Output 3 nab Input banana 2 Output -1 -----Note----- In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
s = input() n = int(input()) symb_cnt = {} for c in s: symb_cnt[c] = symb_cnt[c] + 1 if c in symb_cnt else 1 for cnt in range(1, len(s) + 1): s1 = "" for c in symb_cnt: s1 += c * ((symb_cnt[c] + cnt - 1) // cnt) if len(s1) <= n: for i in range(n - len(s1)): s1 += "a" print(cnt) print(s1) return print(-1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy. -----Input----- The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1. -----Examples----- Input banana 4 Output 2 baan Input banana 3 Output 3 nab Input banana 2 Output -1 -----Note----- In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
s = input() n = int(input()) cnt = {} for c in s: if cnt.get(c) == None: cnt[c] = 1 else: cnt[c] += 1 if n < len(cnt): print(-1) else: ansNum = 0 while True: ansNum += 1 l = 0 char = [] for c, v in cnt.items(): need = (v + ansNum - 1) // ansNum l += need char.append((c, need)) if l > n: continue print(ansNum) ans = "".join([(str(c[0]) * c[1]) for c in char]) ans = ans + "a" * (n - len(ans)) print(ans) break
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy. -----Input----- The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1. -----Examples----- Input banana 4 Output 2 baan Input banana 3 Output 3 nab Input banana 2 Output -1 -----Note----- In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".
s = input() n = int(input()) freq = [(0) for i in range(0, 300)] raport = [(0) for i in range(0, 300)] differentLetters = 0 tickets = 0 sol = "" for c in s: freq[ord(c)] += 1 for i in freq: if i > 0: differentLetters += 1 if differentLetters > n: print("-1") exit() for i in "abcdefghijklmnopqrstuvwxyz": if freq[ord(i)] == 0: continue sol += i freq[ord(i)] -= 1 raport[ord(i)] = freq[ord(i)] for i in range(differentLetters, n): maxRaport = raport[ord("z")] chosenLetter = "z" for j in "abcdefghijklmnopqrstuvwxyz": if raport[ord(j)] > maxRaport: maxRaport = raport[ord(j)] chosenLetter = j sol += chosenLetter raport[ord(chosenLetter)] = freq[ord(chosenLetter)] / sol.count(chosenLetter) for i in sol: a = s.count(i) b = sol.count(i) if a % b == 0: tickets = max(tickets, int(a // b)) else: tickets = max(tickets, int(a // b) + 1) print(tickets) print(sol)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR STRING IF VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR STRING IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR