description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to check if the signal $t$ is similar to $s$.
The original signal $s$ was a sequence of zeros and ones (everyone knows that binary code is the universe-wide language). The returned signal $t$, however, does not look as easy as $s$, but the scientists don't give up! They represented $t$ as a sequence of English letters and say that $t$ is similar to $s$ if you can replace all zeros in $s$ with some string $r_0$ and all ones in $s$ with some other string $r_1$ and obtain $t$. The strings $r_0$ and $r_1$ must be different and non-empty.
Please help Arkady's friend and find the number of possible replacements for zeros and ones (the number of pairs of strings $r_0$ and $r_1$) that transform $s$ to $t$.
-----Input-----
The first line contains a string $s$ ($2 \le |s| \le 10^5$) consisting of zeros and ones — the original signal.
The second line contains a string $t$ ($1 \le |t| \le 10^6$) consisting of lowercase English letters only — the received signal.
It is guaranteed, that the string $s$ contains at least one '0' and at least one '1'.
-----Output-----
Print a single integer — the number of pairs of strings $r_0$ and $r_1$ that transform $s$ to $t$.
In case there are no such pairs, print $0$.
-----Examples-----
Input
01
aaaaaa
Output
4
Input
001
kokokokotlin
Output
2
-----Note-----
In the first example, the possible pairs $(r_0, r_1)$ are as follows: "a", "aaaaa" "aa", "aaaa" "aaaa", "aa" "aaaaa", "a"
The pair "aaa", "aaa" is not allowed, since $r_0$ and $r_1$ must be different.
In the second example, the following pairs are possible: "ko", "kokotlin" "koko", "tlin" | def gethash(l, r):
return (ha[r] - ha[l] * p[r - l] % mod + mod) % mod
def check(lenx, leny):
ha_0 = -1
ha_1 = -1
j = 0
for i in range(m):
if s[i] == "0":
tmp = gethash(j, j + lenx)
if ha_0 == -1:
ha_0 = tmp
elif ha_0 != tmp:
return 0
j += lenx
else:
tmp = gethash(j, j + leny)
if ha_1 == -1:
ha_1 = tmp
elif ha_1 != tmp:
return 0
j += leny
return ha_0 != ha_1
s = list(input())
t = list(input())
m = len(s)
n = len(t)
p = [1]
bas = 2333
mod = (1 << 50) - 2
for i in range(1, n + 1):
p.append(p[i - 1] * bas % mod)
ha = [0]
for i in range(1, n + 1):
ha.append((ha[i - 1] * bas + ord(t[i - 1])) % mod)
cnt_0 = 0
cnt_1 = 0
for x in s:
if x == "0":
cnt_0 += 1
else:
cnt_1 += 1
ans = 0
for i in range(1, n // cnt_0 + 1):
j = n - cnt_0 * i
if j % cnt_1 == 0 and j != 0:
j //= cnt_1
ans += check(i, j)
print(ans) | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal $s$ towards a faraway galaxy. Recently they've received a response $t$ which they believe to be a response from aliens! The scientists now want to check if the signal $t$ is similar to $s$.
The original signal $s$ was a sequence of zeros and ones (everyone knows that binary code is the universe-wide language). The returned signal $t$, however, does not look as easy as $s$, but the scientists don't give up! They represented $t$ as a sequence of English letters and say that $t$ is similar to $s$ if you can replace all zeros in $s$ with some string $r_0$ and all ones in $s$ with some other string $r_1$ and obtain $t$. The strings $r_0$ and $r_1$ must be different and non-empty.
Please help Arkady's friend and find the number of possible replacements for zeros and ones (the number of pairs of strings $r_0$ and $r_1$) that transform $s$ to $t$.
-----Input-----
The first line contains a string $s$ ($2 \le |s| \le 10^5$) consisting of zeros and ones — the original signal.
The second line contains a string $t$ ($1 \le |t| \le 10^6$) consisting of lowercase English letters only — the received signal.
It is guaranteed, that the string $s$ contains at least one '0' and at least one '1'.
-----Output-----
Print a single integer — the number of pairs of strings $r_0$ and $r_1$ that transform $s$ to $t$.
In case there are no such pairs, print $0$.
-----Examples-----
Input
01
aaaaaa
Output
4
Input
001
kokokokotlin
Output
2
-----Note-----
In the first example, the possible pairs $(r_0, r_1)$ are as follows: "a", "aaaaa" "aa", "aaaa" "aaaa", "aa" "aaaaa", "a"
The pair "aaa", "aaa" is not allowed, since $r_0$ and $r_1$ must be different.
In the second example, the following pairs are possible: "ko", "kokotlin" "koko", "tlin" | s = input()
t = input()
n, m = len(s), len(t)
a = s.count("0")
b = len(s) - a
pow = [1] * m
h = [0] * (m + 1)
p, mod = 31, 10**9 + 9
for i in range(1, m):
pow[i] = pow[i - 1] * p % mod
for i in range(m):
h[i + 1] = (h[i] + (ord(t[i]) - ord("a") + 1) * pow[i]) % mod
def get_hash(i, j):
hash_value = (h[j] - h[i] + mod) % mod
hash_value = hash_value * pow[m - i - 1] % mod
return hash_value
def check(x, y):
index = 0
hash_x = hash_y = -1
for i in range(n):
if s[i] == "0":
if hash_x == -1:
hash_x = get_hash(index, index + x)
elif get_hash(index, index + x) != hash_x:
return False
index += x
else:
if hash_y == -1:
hash_y = get_hash(index, index + y)
elif get_hash(index, index + y) != hash_y:
return False
index += y
return hash_x != hash_y
res = 0
for x in range(1, m // a + 1):
if (m - a * x) % b == 0:
y = (m - a * x) // b
if y == 0:
continue
if check(x, y):
res += 1
print(res) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def equi(self, low, high, magnet, n):
while low < high:
mid = (low + high) / 2
tf = 0
for i in range(n):
tf += 1 / (mid - magnet[i])
if abs(tf) < 1e-06:
return mid
elif tf < 0:
high = mid
else:
low = mid
return low
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
getAnswer[i] = self.equi(a[i], a[i + 1], a, n)
def main():
T = int(input())
while T > 0:
n = int(input())
a = [int(x) for x in input().strip().split()]
getAnswer = [0] * n
ob = Solution()
ob.nullPoints(n, a, getAnswer)
for i in range(0, n - 1):
print("{:.2f}".format(getAnswer[i]), end=" ")
print()
T -= 1
if __name__ == "__main__":
main() | CLASS_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def helper(self, a, mid):
ans = 0
for i in range(len(a)):
if mid - a[i] != 0:
ans = ans + 1 / (mid - a[i])
return round(ans, 5)
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
s = a[i]
e = a[i + 1]
while s < e:
mid = (s + e) / 2
eq = 0
for j in a:
if mid - j != 0:
eq += 1 / (mid - j)
eq = round(eq, 5)
if eq > 0:
s = mid
elif eq < 0:
e = mid
else:
getAnswer[i] = mid
break | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
lo = a[i]
hi = a[i + 1]
while round(lo, 2) != round(hi, 2):
mid = (lo + hi) / 2
force = sum(1 / (x - mid) for x in a)
if force == 0:
lo = mid
break
elif force < 0:
lo = mid
else:
hi = mid
getAnswer[i] = round(mid, 2) | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | GREATER = 1
SMALLER = 2
EQUAL = 3
def check(x, i, a, n):
t1 = 0
t2 = 0
for j in range(0, i + 1):
if x == a[j]:
return GREATER
t1 += 1 / (x - a[j])
for j in range(i + 1, n):
if x == a[j]:
return LESSER
t2 += 1 / (a[j] - x)
if t1 == t2:
return EQUAL
return GREATER if t1 > t2 else SMALLER
class Solution:
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
p = a[i]
q = a[i + 1]
while round(p, 2) != round(q, 2):
mid = (p + q) / 2
check_mid = check(mid, i, a, n)
if check_mid == EQUAL:
break
if check_mid == SMALLER:
q = mid
else:
p = mid
getAnswer[i] = round(mid, 2) | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR RETURN VAR VAR VAR VAR CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def calculateForce(self, a, point):
force = 0
for i in a:
force += 1 / (i - point)
return round(force, 5)
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
low = a[i]
high = a[i + 1]
while low <= high:
mid = (low + high) / 2
net_force = self.calculateForce(a, mid)
if net_force == 0:
getAnswer[i] = mid
break
if net_force < 0:
low = mid
else:
high = mid | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR 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 VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | def search(lo, hi, a, n):
mid = (lo + hi) / 2
dis = 0
for i in range(n):
dis += 1 / (mid - a[i])
if abs(dis) < 1e-12:
return mid
if dis > 0:
return search(mid, hi, a, n)
else:
return search(lo, mid, a, n)
class Solution:
def nullPoints(self, n, a, ans):
for i in range(n - 1):
ans[i] = search(a[i], a[i + 1], a, n) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
z = 0
for i in range(n - 1):
left = a[i]
right = a[i + 1]
while True:
mid = (left + right) / 2
equation = self.equilibrium(a, mid)
if equation > 0:
left = mid
elif equation < 0:
right = mid
else:
getAnswer[i] = mid
break
def equilibrium(self, a, mid):
ans = 0
for i in range(len(a)):
if mid - a[i] != 0:
ans = ans + 1 / (mid - a[i])
return round(ans, 5) | CLASS_DEF 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 WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def print(self, *args):
pass
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
fValue = i
bComplete = False
iTryCounter = 0
iXLeft = a[i]
iXRight = a[i + 1]
iXMid = (iXLeft + iXRight) / 2
while bComplete == False:
iTryCounter += 1
if iTryCounter > 20:
getAnswer[i] = iXMid
bComplete = True
iXMid = (iXLeft + iXRight) / 2
self.print("l m r", iXLeft, iXMid, iXRight)
iResultLeft = 0
iResultRight = 0
for l in range(0, i + 1):
iResultLeft += 1 / (iXMid - a[l])
for r in range(i + 1, n):
iResultRight += 1 / (a[r] - iXMid)
iResultDiff = iResultRight - iResultLeft
self.print("res l r diff", iResultLeft, iResultRight, iResultDiff)
fDiffMin = 5e-06
if abs(iResultDiff) < fDiffMin:
self.print("abs iResultDiff < fDiffMin", fDiffMin, iResultDiff)
getAnswer[i] = iXMid
bComplete = True
elif iResultDiff < 0:
iXLeft = iXMid
else:
iXRight = iXMid
self.print("end comp l m r", bComplete, iXLeft, iXMid, iXRight)
self.print(getAnswer) | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, l, ans):
def fun(i, j):
while i < j:
mid = (i + j) / 2
c = 0
for k in range(n):
c += 1 / (l[k] - mid)
if abs(c) <= 1e-06:
return round(mid, 2)
if c > 0:
j = mid
else:
i = mid
return i
for k in range(n - 1):
ans[k] = fun(l[k], l[k + 1]) | CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
def bs(a, start, end, mid):
ans = 0
for i in range(n):
if mid - a[i] != 0:
ans += 1 / (mid - a[i])
return round(ans, 5)
for i in range(n - 1):
start = a[i]
end = a[i + 1]
while True:
mid = (start + end) / 2
point = bs(a, start, end, mid)
if point < 0:
end = mid
elif point > 0:
start = mid
else:
getAnswer[i] = mid
break | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
z = 0
for i in range(n - 1):
start = a[i]
end = a[i + 1]
while True:
mid = (start + end) / 2
eq = self.equilibrium(a, mid)
if eq > 0:
start = mid
elif eq < 0:
end = mid
else:
getAnswer[i] = mid
break
def equilibrium(self, a, mid):
ans = 0
for i in range(len(a)):
if mid - a[i] != 0:
ans = ans + 1 / (mid - a[i])
return round(ans, 5)
def main():
T = int(input())
while T > 0:
n = int(input())
a = [int(x) for x in input().strip().split()]
getAnswer = [0] * n
ob = Solution()
ob.nullPoints(n, a, getAnswer)
for i in range(0, n - 1):
print("{:.2f}".format(getAnswer[i]), end=" ")
print()
T -= 1
if __name__ == "__main__":
main() | CLASS_DEF 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 WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def calc(self, a, n, mid):
ans = 0
for i in range(n):
if a[i] < mid:
ans += 1 / (mid - a[i])
else:
ans -= 1 / (a[i] - mid)
return ans
def search(self, a, i, n):
lo, hi = a[i], a[i + 1]
while hi - lo > 1e-06:
mid = (lo + hi) / 2
v = self.calc(a, n, mid)
if v > 0:
lo = mid
else:
hi = mid
return lo
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
getAnswer[i] = self.search(a, i, n) | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, N, M, getAnswer):
res = []
def BinSearch(left, right, min_val, max_val):
distance = (min_val + max_val) / 2
left_res = sum([(1 / abs(distance - point)) for point in left])
right_res = sum([(1 / abs(point - distance)) for point in right])
end_force = left_res - right_res
if -1e-06 < end_force < 1e-06:
return distance
elif end_force < 0:
return BinSearch(left, right, min_val, distance)
return BinSearch(left, right, distance, max_val)
for ind in range(1, N):
left = M[:ind]
right = M[ind:]
getAnswer[ind - 1] = float(
"{:.2f}".format(BinSearch(left, right, M[ind - 1], M[ind]))
)
return getAnswer | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def sigmaForce(self, x, a):
netForce = 0
for i in a:
netForce += 1 / (x - i)
return netForce
def bs(self, l, r, a):
while r - l >= 1e-06:
x = l + (r - l) / 2
netForce = self.sigmaForce(x, a)
if netForce > 0:
l = x
else:
r = x
return r
def nullPoints(self, n, a, getAnswer):
points = []
for i in range(len(a) - 1):
l, r = a[i], a[i + 1]
getAnswer[i] = self.bs(l, r, a)
return points | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
def sol(i, j, a, n):
l = a[i]
r = a[j]
left = l
right = r
while right - left >= 1e-06:
fl = 0
fr = 0
m = (left + right) / 2
for k in range(n):
if k <= i:
fr += 1 / (m - a[k])
else:
fl += 1 / (a[k] - m)
if fl < fr:
left = m
else:
right = m
return left
for i in range(n - 1):
getAnswer[i] = sol(i, i + 1, a, n) | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def solve(self, a, n, low, high):
while low < high:
mid = (low + high) / 2
force = 0
for i in range(n):
force += 1 / (mid - a[i])
force = round(force, 5)
if abs(force) < 1e-06:
return round(mid, 2)
if force > 0:
low = mid
else:
high = mid
return round(low, 2)
def nullPoints(self, n, a, getAnswer):
for i in range(n - 1):
getAnswer[i] = self.solve(a, n, a[i], a[i + 1]) | CLASS_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
for i in range(0, n - 1):
getAnswer[i] = self.check(a, n, a[i], a[i + 1])
def check(self, a, n, low, hig):
while low <= hig:
mid = (hig + low) / 2
force = 0
for i in range(n):
force += 1 / (mid - a[i])
if abs(force) < 1e-06:
return mid
elif force > 0:
low = mid
else:
hig = mid
return low | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | import sys
sys.setrecursionlimit(10**5)
class Solution:
def bin_search(self, s, e, l, r, a):
if abs(s - e) >= 1e-06:
mid = (e + s) / 2
lp = rp = 0
for i in range(l):
lp += 1 / abs(a[i] - mid)
for i in range(l, r):
rp += 1 / abs(a[i] - mid)
if abs(lp - rp) <= 1e-06:
return mid
if lp < rp:
return self.bin_search(s, mid, l, r, a)
else:
return self.bin_search(mid, e, l, r, a)
return s
def nullPoints(self, n, a, getAnswer):
for i in range(1, n):
getAnswer[i - 1] = self.bin_search(a[i - 1], a[i], i, n, a)
return getAnswer | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
arr = []
def eq(num):
ans = 0
for i in a:
if i < num:
ans += 1 / (num - i)
else:
ans -= 1 / (i - num)
return ans
for i in range(1, n):
low, high = a[i - 1], a[i]
while low < high:
mid = (low + high) / 2
temp = eq(mid)
if abs(temp) < 1e-06:
break
elif temp < 0:
high = mid
else:
low = mid
getAnswer[i - 1] = mid | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, getAnswer):
def left(i, m):
f = 0
for j in range(i, n):
f += 1 / (a[j] - m)
return f
def right(i, m):
f = 0
for j in range(i - 1, -1, -1):
f += 1 / (m - a[j])
return f
for i in range(n - 1):
l, r = a[i], a[i + 1]
while l <= r:
m = (l + r) / 2
f1, f2 = left(i, m), right(i, m)
if abs(f1 - f2) < 1e-06:
break
elif f1 < f2:
l = m
else:
r = m
getAnswer[i] = m | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR |
Given N Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force being equal to the inverse of the distance (1/d , d being the distance). Now given the positions of the magnets, the task to find all the points along the linear line where net force is ZERO.
More Formally, Magnets are placed on X axis, the coordinates of which are given, you are asked to find out the X-co-ordinates of all the equilibrium points (i.e. the point where net force is zero). You notice the point each magnet repels each other, it means the polarity of the magnet is such that exerts +ve force in its right side and -ve force in left side, (here +ve is considered in +ve direction of x-axis). And that forces are inversely proportional to the distance, thus there lies an equilibrium point between every two magnetic points. Thus there will be total of N-1 equllibrium points. You have to find those N-1 points.
Note: Array M[] is sorted and distance have to be calculated with precision of 2 decimal places.
Example 1:
Input:
N = 2
M[] = {1, 2}
Output:
1.50
Explanation:
The mid point of two points will have
net force zero, thus answer = 1.50
Example 2:
Input:
N = 4
M[] = {0, 10, 20, 30}
Output:
3.82, 15.00, 26.18
Your Task:
You don't need to read input or print anything. Your task is to complete the function nullPoints() which takes the array M[], its size N as inputs and an answer array getAnswer[] to store the points having net force zero till precised two decimal places.
Expected Time Complexity: O(N^{2} * Log(N))
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^{5}
0 ≤ M[1] < ....M[i] < M[i+1] < ....M[N] ≤ 10^{6} | class Solution:
def nullPoints(self, n, a, ans):
for i in range(n - 1):
fi, si = i, i + 1
l, r = a[fi], a[si]
while l < r:
mid = (l + r) / 2
force = sum(1 / (mid - v) for v in a if mid - v != 0)
if abs(force) < 1e-07:
ans[i] = mid
break
elif force < 0:
r = mid
else:
l = mid | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | s = set()
d = {}
s.add(0)
for _ in range(int(input())):
sign, x = map(str, input().split())
x = int(x)
if sign == "+":
s.add(x)
else:
if x not in d:
d[x] = x
while d[x] in s:
d[x] += x
print(d[x]) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | n = int(input())
P = {}
Si = {}
for i in range(n):
S = input()
a = S[0]
x = int(S[1:])
if a == "+":
P[x] = True
else:
if x in Si:
a = Si[x]
else:
a = x
while a in P:
a += x
Si[x] = a
print(a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | T = int(input())
s = {0}
d = {}
for _ in range(T):
ch, n = input().split()
n = int(n)
if ch == "+":
s.add(n)
elif ch == "?":
if n not in d:
d[n] = n
while d[n] in s:
d[n] += n
print(d[n]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | a, b = dict(), dict()
for _ in range(int(input())):
s, x = list(input().split())
x = int(x)
if s == "+":
a[x] = True
else:
if x in b:
y = b[x]
else:
y = x
while y in a:
y += x
b[x] = y
print(y) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | dic = {}
for jj in range(int(input())):
a, b = input().split()
k = int(b)
if a == "+":
dic[k] = 0
for i in range(k, 10**37, k):
if i not in dic:
dic[k] = i
break
elif k not in dic:
print(k)
else:
for i in range(dic[k], 10**37, k):
if i not in dic:
dic[k] = i
print(i)
break | ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | last = {}
s = set()
q = int(input())
for i in range(q):
qt, num = input().split()
num = int(num)
if qt == "+":
s.add(num)
else:
if num in last:
k = last[num]
else:
k = num
while k in s:
k += num
last[num] = k
print(k) | ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | x = int(input())
y = set()
q = {}
while x:
x -= 1
op, m = input().split()
m = int(m)
if op == "+":
y.add(m)
continue
f = q.get(m, m)
while f in y:
f += m
q[m] = f
print(f) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | dic = dict()
s = set()
for _ in range(int(input())):
op, n = input().split()
n = int(n)
if op == "+":
s.add(n)
else:
m = n
if m in dic:
m = dic[n]
while True:
if m not in s:
print(m)
dic[n] = m
break
m = m + n | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | a = int(input())
s = set()
sl = {}
s.add(0)
sp = []
for i in range(a):
x = input()
ni = 0
x1 = ""
x2 = ""
for j in x:
if j != " " and x[0] != "?" and j != x[0]:
x1 += j
ni += 1
elif j != " " and x[0] != "+" and j != x[0]:
x2 += j
if ni >= 1:
x11 = int(x1)
s.add(x11)
else:
x12 = int(x2)
if x12 in sl:
na = sl[x12]
else:
na = x12
while na in s:
na += x12
sp.append(na)
sl[x12] = na
for i in sp:
print(i) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER STRING VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER STRING VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | map1, map2 = [{}, {}]
for test_cases in range(int(input())):
type, val = list(input().split())
ans = 0
val = int(val)
if type == "+":
map1[val] = True
else:
if val in map2:
fuck = map2[val]
else:
fuck = val
while fuck in map1:
fuck = fuck + val
map2[val] = fuck + 0
ans = fuck + 0
print(ans) | ASSIGN VAR VAR LIST DICT DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | n = int(input())
HashSet = set()
HashMap = dict()
for i in range(n):
operator, num = map(str, input().split())
if operator == "+":
HashSet.add(int(num))
else:
num = int(num)
if num not in HashMap:
HashMap[num] = num
while HashMap[num] in HashSet:
HashMap[num] += num
print(HashMap[num]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | s = set([0])
ans = {}
q = int(input())
def add(x):
s.add(x)
def ask(x):
if ans.get(x) == None:
ans[x] = x
while ans[x] in s:
ans[x] += x
print(ans[x])
for i in range(q):
c, x = input().split()
if c == "+":
add(int(x))
else:
ask(int(x)) | ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | s = set()
d = {}
for _ in range(int(input())):
c, a = input().split()
a = int(a)
if c == "+":
s.add(a)
else:
bg = 1
if a in d.keys():
bg = d[a]
for i in range(bg, 100000000):
if a * i not in s:
print(a * i)
d[a] = i
break | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR |
This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.
Initially you have a set containing one element — $0$. You need to handle $q$ queries of the following types:
+ $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
-----Input-----
The first line contains an integer $q$ ($1 \leq q \leq 2 \cdot 10^5$) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ($1 \leq x \leq 10^{18}$). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ($1 \leq k \leq 10^{18}$).
It is guaranteed that there will be at least one query of type ?.
-----Output-----
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
-----Examples-----
Input
15
+ 1
+ 2
? 1
+ 4
? 2
+ 6
? 3
+ 7
+ 8
? 1
? 2
+ 5
? 1
+ 1000000000000000000
? 1000000000000000000
Output
3
6
3
3
10
3
2000000000000000000
Input
6
+ 100
? 100
+ 200
? 100
+ 50
? 50
Output
200
300
150
-----Note-----
In the first example:
After the first and second queries, the set will contain elements $\{0, 1, 2\}$. The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$.
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$. The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$.
In the second example:
Initially, the set contains only the element $\{0\}$.
After adding an integer $100$ the set contains elements $\{0, 100\}$.
$100\text{-mex}$ of the set is $200$.
After adding an integer $200$ the set contains elements $\{0, 100, 200\}$.
$100\text{-mex}$ of the set is $300$.
After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$.
$50\text{-mex}$ of the set is $150$. | q = int(input())
s = {0}
mp = dict()
for qq in range(q):
ch, x = input().split()
x = int(x)
if ch == "+":
s.add(x)
else:
y = x
if x in mp:
y = mp[x]
while True:
if y not in s:
print(y)
mp[x] = y
break
y += x | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if k >= m - 1:
ans = 0
for i in range(n):
if i <= m - 1 or n - i - 1 <= m - 1:
ans = max(ans, a[i])
print(ans)
return
ans = 0
for i in range(k + 1):
ost = k - i
ost = n - ost
b = a[i:ost]
all = m - 1 - k
cur = 1000000000.0
for j in range(all + 1):
left = j
right = all - left
left = b[left]
right = b[len(b) - right - 1]
cur = min(cur, max(left, right))
ans = max(ans, cur)
print(ans)
t = int(input())
while t > 0:
t -= 1
solve() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | R = lambda: list(map(int, input().split()))
for _ in range(int(input())):
n, m, k = R()
a = R()
k = min(k, m - 1)
d = m - k
ans = 0
for i in range(k + 1):
p = 10**9
for j in range(d):
p = min(p, max(a[i + j], a[i + n - k - 1 - (d - 1 - j)]))
ans = max(ans, p)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
al = list(map(int, input().split()))
mind = min(m - 1, k)
ans = 0
for i in range(mind + 1):
d = al[i : n - (mind - i)]
p = m - mind - 1
l = []
for j in range(p + 1):
g = d[j : len(d) - (p - j)]
l.append(max(g[0], g[-1]))
ans = max(min(l), ans)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | for i in range(int(input())):
n, m, k = map(int, input().split())
k = min(k, m - 1)
a = list(map(int, input().split()))
b = [max(a[i], a[i + n - m]) for i in range(0, m)]
x = max(min(b[i : i + (m - k)]) for i in range(k + 1))
print(x) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def Input():
tem = input().split()
ans = []
for it in tem:
ans.append(int(it))
return ans
T = Input()[0]
for t in range(T):
n, m, k = Input()
a = Input()
if k + 1 >= m:
l, r = 0, n - m
ans = -10000000000000
while r < n:
ans = max(ans, a[l], a[r])
l += 1
r += 1
print(ans)
else:
b = []
l, r = 0, n - m
while r < n:
b.append(max(a[l], a[r]))
l += 1
r += 1
l, r = 1, m - k
que = []
max_que = []
for i in range(m - k):
que.append([b[i], i])
while len(max_que) > 0 and max_que[-1][0] >= b[i]:
max_que.pop()
max_que.append([b[i], i])
ans = max_que[0][0]
while r < m:
que.append([b[r], r])
while len(max_que) > 0 and max_que[-1][0] >= b[r]:
max_que.pop()
max_que.append([b[r], r])
while que[0][1] >= max_que[0][1]:
del max_que[0]
del que[0]
ans = max(ans, max_que[0][0])
l += 1
r += 1
print(ans) | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR WHILE VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def find_optimum(length, pos, fix, arr):
if pos < length // 2:
arr = arr[:pos] + arr[length - pos :]
length = len(arr)
if fix > pos - 1:
fix = pos - 1
picks = []
for i in range(pos):
picks += [max(arr[i], arr[i + length - pos])]
pick_range = pos - fix
optimal = 0
for i in range(fix + 1):
m = min(picks[i : i + pick_range])
if m > optimal:
optimal = m
return optimal
t = int(input())
for i in range(t):
n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(find_optimum(n, m, k, a)) | FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
t = int(sys.stdin.readline())
ans_arr = []
for x in range(t):
[n, m, k] = [int(j) for j in sys.stdin.readline().split()]
a = [int(g) for g in sys.stdin.readline().split()]
if m - 1 > k:
ans = -2
for i in range(k + 1):
tmp = pow(10, 9) + 10
for j in range(m - k):
val = max(a[i + j], a[i + j + n - m])
tmp = min(tmp, val)
ans = max(ans, tmp)
ans_arr.append(str(ans))
else:
ans = 0
for g in range(m):
ans = max(ans, a[g])
for h in range(n - 1, n - 1 - m, -1):
ans = max(ans, a[h])
ans_arr.append(str(ans))
print("\n".join(ans_arr)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def f():
n, m, k = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
maxA = 1
for a in A:
maxA = max(maxA, a)
limit = min(m - 1, k)
free = m - 1 - limit
ans = 1
for a0 in range(limit + 1):
minX = maxA
for a in range(a0, a0 + free + 1):
b = m - 1 - a
x = max(A[a], A[-b - 1])
minX = min(minX, x)
ans = max(ans, minX)
return ans
T = int(input())
for t in range(T):
print(f()) | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
t = input()
def solve(n, m, k, nums):
ans = 0
new_k = min(m - 1, k)
for kk in range(new_k + 1):
left = kk
right = new_k - kk
temp = nums[left : len(nums) - right]
c = min([max(temp[i], temp[-(m - new_k - i)]) for i in range(m - new_k)])
ans = max(ans, c)
return ans
for _ in range(int(t)):
temp = [int(s) for s in sys.stdin.readline().split(" ")]
n = temp[0]
m = temp[1]
k = temp[2]
nums = [int(s) for s in sys.stdin.readline().split(" ")]
print(solve(n, m, k, nums)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | class Solution(object):
def minSlidingWindow(self, nums, k):
monotonicQueue = []
res = []
for i in range(len(nums)):
while monotonicQueue and nums[monotonicQueue[-1]] >= nums[i]:
monotonicQueue.pop()
monotonicQueue.append(i)
if monotonicQueue[0] == i - k:
monotonicQueue.pop(0)
if i >= k - 1 or i + 1 >= len(nums):
res.append(nums[monotonicQueue[0]])
return res
def k0case(n, m, a):
res = n - m + 1
ans = max(a[0], a[n - m])
heap = []
for i in range(m):
j = i + res - 1
ans = min(ans, max(a[i], a[j]))
heap.append(max(a[i], a[j]))
return heap
def kmaxcase(n, m, a):
res = n - m + 1
ans = max(a[0], a[n - m])
for i in range(m):
j = i + res - 1
ans = max(ans, max(a[i], a[j]))
return ans
def withkcase(n, m, k, a):
if k >= m - 1:
return kmaxcase(n, m, a)
res = m - k
ans = float("-inf")
sol = Solution()
A = [max(a[i], a[n - m + i]) for i in range(m)]
ans = sol.minSlidingWindow(A, res)
ans = max(ans)
return ans
t = int(input())
for _ in range(t):
n, m, k = [int(s) for s in input().split(" ")]
a = [int(s) for s in input().split(" ")]
print(withkcase(n, m, k, a)) | CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def check(arr, m):
n = len(arr)
min_val = float("inf")
for i in range(m):
min_val = min(min_val, max(arr[i], arr[n - m + i]))
arr.reverse()
for i in range(m):
min_val = min(min_val, max(arr[i], arr[n - m + i]))
if min_val == float("inf"):
return 0
return min_val
def solve(arr, n, m, k, ans):
max_val = 0
if m <= k:
max_val = max(arr[:m])
arr.reverse()
max_val = max(max_val, max(arr[:m]))
else:
m -= k
for i in range(k + 1):
arr1 = arr[i : i + n - k]
max_val = max(max_val, check(arr1, m))
ans.append(max_val)
def main():
ans = []
t = int(input())
for i in range(t):
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
solve(arr, n, m, k, ans)
for i in ans:
print(i)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR FUNC_CALL VAR STRING RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
before = m - 1
k = min(k, m)
temp = [max(a[i], a[n + i - 1 - before]) for i in range(before + 1)]
if k >= before:
print(max(temp))
elif k == 0:
print(min(temp))
else:
temp2 = [min(temp[j : before + 1 - k + j]) for j in range(k + 1)]
print(max(temp2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for _ in range(t):
n, m, k = tuple(map(int, input().split()))
l = list(map(int, input().split()))
M = max(l)
k = min(k, m - 1)
realp = m - k - 1
ma = -1
for i in range(k + 1):
tmp = M
for j in range(realp + 1):
tmp = min(tmp, max(l[i + j], l[i + j + n - m]))
ma = max(ma, tmp)
print(ma) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def chek(x, li, l):
mn = max(li[0], li[l - 1])
for i in range(x + 1):
mx = max(li[i], li[l + i - 1])
mn = min(mn, mx)
return mn
t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
ar = list(map(int, input().split()))
b = 0
x = m - 1 - k
l = n - k
y = n - (m - 1)
if x <= 0:
print(max(max(ar[:m]), max(ar[n - m :])))
continue
for j in range(k + 1):
a = chek(x, ar[j : j + l], y)
b = max(a, b)
print(b) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for i in range(t):
n, m, k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
if k >= m:
k = m - 1
z = m - 1 - k
sol = []
for j in range(k + 1):
big = max(a[j], a[j - k - z - 1])
for o in range(z + 1):
if max(a[j + o], a[o + j - k - z - 1]) < big:
big = max(a[j + o], a[o + j - k - z - 1])
sol.append(big)
print(max(sol)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | a = int(input())
for i in range(a):
n, m, k = map(int, input().split())
z = list(map(int, input().split()))
if m - 1 <= k:
ans1 = z[::-1]
print(max(max(z[0:m]), max(ans1[0:m])))
else:
alpha = []
for i in range(k + 1):
ans = z[i : len(z) - (k - i)]
t = m - k - 1
kapa = []
for i in range(t + 1):
kapa.append(max(ans[i], ans[-1 * (t - i + 1)]))
alpha.append(min(kapa))
print(max(alpha)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | from sys import stdin
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
arr = []
for i in range(int(stdin.readline())):
n, m, k = arr_inp(1)
a, ans = arr_inp(1), 0
if m == 1:
arr.append(str(max(a[0], a[-1])))
continue
if k >= m:
k = m - 1
for j in range(k + 1):
tem, z, num = float("inf"), n - k - 1 + j, m - k - 1
for c in range(j, j + (m - k)):
tem = min(tem, max(a[c], a[z - num]))
num -= 1
ans = max(tem, ans)
arr.append(str(ans))
print("\n".join(arr)) | FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR STRING BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
input = sys.stdin.readline
t = int(input())
for _ in [0] * t:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
l = n - m + 1
ma = [0] * (n - l + 1)
for i in range(n - l + 1):
if a[i] > a[i + l - 1]:
ma[i] = a[i]
else:
ma[i] = a[i + l - 1]
ha = k
if ha >= m:
ha = m - 1
w = n - l + 1 - ha
mi = [10**10] * (n - l - w + 2)
for i in range(n - l - w + 2):
for j in range(w):
if mi[i] > ma[i + j]:
mi[i] = ma[i + j]
print(max(mi)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
input = sys.stdin.readline
def f(p, b, c):
j = 0
d = []
while j <= p:
q = max(b[j], c[p - j])
d.append(q)
j += 1
return min(d)
def f1(p, b, c):
j = 0
d = []
while j <= p:
q = max(b[j], c[p - j])
d.append(q)
j += 1
return max(d)
t = int(input())
for i in range(t):
n, m, k = map(int, input().split())
b = list(map(int, input().split()))
p = m - 1
c = b.copy()
c.reverse()
j = 0
d = []
if k >= p:
print(f1(p, b, c))
else:
ms = -1
while j <= k:
y = f(p - k, b[j:], c[k - j :])
if y > ms:
ms = y
j += 1
print(ms) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def solve():
n, m, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
maxg = None
if k >= m:
k = m - 1
for start in range(k + 1):
end = n - (k - start) - 1
max_val = None
left = None
if m <= k + 1:
left = 0
else:
left = m - k - 1
for i in range(left + 1):
j = left - i
temp = max(arr[start + i], arr[end - j])
if max_val is None:
max_val = temp
elif temp < max_val:
max_val = temp
if maxg is None:
maxg = max_val
elif max_val > maxg:
maxg = max_val
print(maxg)
t = int(input())
while t:
t = t - 1
solve() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input().rstrip())
for i in range(t):
n, m, k = map(int, input().rstrip().split())
k = min(k, m - 1)
nums = list(map(int, input().rstrip().split()))
pk = tuple(max(nums[i], nums[i + (n - m)]) for i in range(m))
best = 0
for j in range(k + 1):
best = max(best, min(pk[j : j + m - k]))
print(best) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | 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, M, K = MAP()
A = LIST()
K = min(K, M - 1)
L = M - K - 1
ans = 0
for i in range(K + 1):
j = N - K + i
mn = INF
for k in range(L + 1):
l = L - k
mx = max(A[i + k], A[j - l - 1])
mn = min(mn, mx)
ans = max(ans, mn)
print(ans) | 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 VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | for _ in range(int(input())):
n, me, k = map(int, input().split())
a = list(map(int, input().split()))
sz = n - min(k, me - 1)
before = max(0, me - k - 1)
ret = -float("inf")
for i in range(0, n - sz + 1):
t = a[i : i + sz]
cur = float("inf")
for left in range(before + 1):
right = sz - (before - left + 1)
cur = min(cur, max(t[left], t[right]))
ret = max(ret, cur)
print(ret) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
def slv():
n, m, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
ntr = max(0, m - k - 1)
k = min(k, m - 1)
sls = 0
for i in range(k + 1):
la = 10000000000.0
for j in range(ntr + 1):
la = min(la, max(a[i + j], a[len(a) - (k - i) - (ntr - j) - 1]))
sls = max(sls, la)
print(sls)
for _ in range(t):
slv() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for y in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if k >= m - 1:
ans = max(max(a[:m]), max(a[n - m :]))
else:
i = k
j = 0
ans = 0
while i >= 0:
ind1 = i + (m - k) - 1
ind2 = n - j - 1
res2 = 1000000000.0 + 3
for kk in range(m - k):
res = max(a[ind1 - kk], a[ind2 - kk])
res2 = min(res, res2)
ans = max(ans, res2)
i -= 1
j += 1
print(int(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
input = sys.stdin.readline
t = int(input())
class SegTree:
def segfunc(self, x, y):
return min(x, y)
def __init__(self, n, ide_ele, init_val):
self.ide_ele = ide_ele
self.num = 2 ** (n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
for _ in range(t):
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * M
for l in range(M):
r = M - l - 1
dp[l] = max(a[l], a[-1 - r])
res = 0
if K >= M - 1:
print(max(dp))
continue
if K == 0:
print(min(dp))
continue
seg = SegTree(M, 10**10, dp)
for l in range(K):
tt = seg.query(l, min(M, l + M - K))
res = max(res, tt)
dp.reverse()
seg = SegTree(M, 10**10, dp)
for l in range(K):
tt = seg.query(l, min(M, l + M - K))
res = max(res, tt)
print(res) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
def remchoice(a2, rem):
ans = float("inf")
for i in range(rem + 1):
ans = min(ans, max(a2[i], a2[-rem + i - 1]))
return ans
for i in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if m - 1 <= k:
print(max(max(a[:m]), max(a[-m:])))
else:
rem = m - 1 - k
ans = 0
for j in range(k + 1):
ans = max(ans, remchoice(a[j : n - (k - j)], rem))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def ma(x):
return max(x[0], x[-1])
z = int(input())
for zz in range(z):
n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
segs = []
x = n - m + 1
for i in range(m):
segs.append(a[i : i + x])
x = len(segs)
for i in range(x):
segs[i] = ma(segs[i])
tm = max(a) + 1
res = -1
st = max(0, m - k - 1)
for i in range(min(k + 1, m)):
te = min(i, k)
si = max(te, i - st)
te2 = max(x - k - 1, i + m)
ei = min(te2, i + st)
r = min(segs[si : ei + 1])
res = max(res, r)
print(res) | FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
k = min(k, m - 1)
a = list(map(int, input().split()))
b = []
for i in range(m):
b.append(max(a[i], a[i + n - m]))
sz = m - k
ans = 0
j = 0
q = []
for i in range(k + 1):
while q and q[0] < i:
q.pop(0)
while j < i + sz:
while q and b[q[-1]] >= b[j]:
q.pop()
q.append(j)
j += 1
ans = max(ans, b[q[0]])
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR BIN_OP VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def resolve():
n, pos, control = map(int, input().split())
before = pos - 1
behind = n - pos
control = min(before, control)
uncontrol = pos - 1 - control
line = list(map(int, input().split()))
best = 0
for my_first in range(control + 1):
strategy = float("inf")
for op_first in range(uncontrol + 1):
case_ans = max(
line[my_first + op_first], line[my_first + op_first + behind]
)
strategy = min(strategy, case_ans)
best = max(best, strategy)
print(best)
n = int(input())
while n:
n -= 1
resolve() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | for _ in range(int(input())):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
k = min(k, m - 1)
best = 0
before = m - 1
behind = n - m
for x in range(k + 1):
sans = float("inf")
for y in range(m - k):
cans = max(a[x + y], a[n - (m - x - y)])
sans = min(sans, cans)
best = max(best, sans)
print(best) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
def solve(n, m, k, arr):
if m - 1 <= k:
return max(max(arr[:m]), max(arr[n - m :]))
else:
res = 0
for l in range(k + 1):
r = k - l
worst_case = 10**9 + 1
for ll in range(m - 1 - k + 1):
rr = m - 1 - k - ll
head = arr[l + ll]
tail = arr[n - 1 - r - rr]
worst_case = min(worst_case, max(head, tail))
res = max(res, worst_case)
return res
for _ in range(t):
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
print(solve(n, m, k, arr)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def inp(dtype=str, strip=True):
s = input()
res = [dtype(p) for p in s.split()]
res = res[0] if len(res) == 1 and strip else res
return res
def problemA():
t = int(input())
for _ in range(t):
n = int(input())
s = input()
s = [int(el) for el in s]
res = "-1"
cum = sum(s)
i = 1
while i <= n:
if s[-i] % 2 != 0 and cum % 2 == 0:
res = "".join([str(s[j]) for j in range(n - i + 1)])
break
cum -= s[-i]
i += 1
print(res)
def problemB():
t = int(input())
for tcase in range(t):
n = int(input())
a = inp(int, strip=False)
next = a[0] + 1 if a[0] <= 0 else 1
i = 1
while i < n and a[i] >= next:
if a[i] < 0:
next = a[i] + 1
elif next <= 0:
next = 1
else:
next += 1
i += 1
if i == n:
print("YES")
continue
ileft = i - 1
gapleft = a[ileft] < next - 1
i = n - 1
next = a[i] + 1 if a[i] <= 0 else 1
i -= 1
while i >= 0 and a[i] >= next:
if a[i] < 0:
next = a[i] + 1
elif next <= 0:
next = 1
else:
next += 1
i -= 1
if i < 0:
print("YES")
continue
iright = i + 1
gapright = a[iright] < next - 1
if ileft + 1 > iright:
print("YES")
elif ileft + 1 == iright:
if a[ileft] != a[iright]:
print("YES")
elif a[ileft] > 0 and (gapleft or gapright):
print("YES")
else:
print("NO")
else:
print("NO")
def problemC():
t = int(input())
for _ in range(t):
n, m, k = inp(int)
k = min(k, m - 1)
a = inp(int, strip=False)
b = [max(a[i], a[i + (n - m)]) for i in range(0, m)]
x = max(min(b[i : i + (m - k)]) for i in range(k + 1))
print(x)
problemC() | FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR 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 VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def main():
def solve():
n, m, k = map(int, input().split())
aa = [int(a) for a in input().split()]
k = min(k, m - 1)
u = m - k - 1
best = 0
for f in range(k + 1):
b = n - k + f
worst = 10000000000.0 + 1
for j in range(0, u + 1):
w = max(aa[f + j], aa[b - u + j - 1])
if w < worst:
worst = w
if worst > best:
best = worst
print(best)
q = int(input())
for _ in range(q):
solve()
main() | FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | for _ in range(int(input())):
n, m, k = list(map(int, input().split()))
l = list(map(int, input().split()))
mi = 0
for i in range(min(k, m - 1) + 1):
temp = 100000000000
for j in range(m - min(k, m - 1)):
temp = min(temp, max(l[i + j], l[n - m + i + j]))
mi = max(mi, temp)
print(mi) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
input = sys.stdin.readline
nn = int(input())
for i in range(nn):
n, m, k = map(int, input().split())
k = min(k, m - 1)
A = list(map(int, input().split()))
B = []
for i in range(m):
B.append(max(A[i], A[n - m + i]))
ans = -float("inf")
for i in range(k + 1):
ans = max(ans, min(B[i : len(B) - k + i]))
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for i in range(t):
n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)
arr = list(map(int, input().split()))
L = min(m - 1, k)
arr1 = []
for i in range(L + 1):
min1 = max(arr[i], arr[n - 1 - (m - 1 - i)])
for j in range(0, m - L):
if max(arr[i + j], arr[n - 1 - (m - 1 - (i + j))]) < min1:
min1 = max(arr[i + j], arr[n - 1 - (m - 1 - (i + j))])
arr1.append(min1)
print(max(arr1)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
class CMindControl:
def solve(self):
for _ in range(int(input())):
n, m, k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
reachable_set = set()
for i in range(m):
reachable_set.add(i)
reachable_set.add(n - 1 - i)
reachable_sorted = []
for idx in reachable_set:
reachable_sorted.append([a[idx], idx])
reachable_sorted.sort()
if k >= m - 1:
ans = reachable_sorted[-1][0]
print(ans)
continue
global_ans = 0
for i in range(k + 1):
j = n - 1 + i - k
cur_ans = float("inf")
for u in range(i, i + m - 1 - k + 1):
v = j + u - (m - 1 - k) - i
cur_ans = min(cur_ans, max(a[u], a[v]))
global_ans = max(global_ans, cur_ans)
print(global_ans)
solver = CMindControl()
input = sys.stdin.readline
solver.solve() | IMPORT CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | V, IDX = [0] * 3501, [0] * 3501
def solve(A, n, m, k):
d = n - m
B = [0] * m
for i in range(m):
B[i] = max(A[i], A[i + d])
w = max(1, m - k)
res = 0
l = r = 0
for i in range(m):
while r > l and V[r - 1] >= B[i]:
r -= 1
V[r], IDX[r] = B[i], i
r += 1
if IDX[l] == i - w:
l += 1
if i >= w - 1:
res = max(res, V[l])
return res
n = int(input())
for i in range(n):
n, m, k = map(int, input().split())
A = list(map(int, input().strip().split()))
print(solve(A, n, m, k)) | ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
n, m, k = list(map(int, sys.stdin.readline().rstrip().split(" ")))
s = list(map(int, sys.stdin.readline().rstrip().split(" ")))
if k >= m:
k = m - 1
sol2 = []
for i in range(k + 1):
l = n - k + i - 1
f = i
sol = []
for j in range(m - k):
f2 = f + j
l2 = l - (m - k - 1 - j)
sol.append(max([s[f2], s[l2]]))
sol2.append(min(sol))
print(max(sol2)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
k = min(k, m - 1)
a = list(map(int, input().split()))
glob_ans = 0
for start_eat in range(k + 1):
l_bound, r_bound = start_eat, n - k + start_eat
free = m - 1 - k
ans = max(a[l_bound], a[r_bound - 1 - free])
for i in range(free + 1):
ans = min(ans, max(a[l_bound + i], a[r_bound - 1 - free + i]))
glob_ans = max(glob_ans, ans)
print(glob_ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
input = sys.stdin.readline
def getInt():
return int(input())
def getVars():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getStr():
return input().strip()
def foo(b, before, m):
m1 = 10**9
for j in range(m - before):
m1 = min(m1, max(b[j], b[j + len(b) - (m - before)]))
return m1
t = getInt()
for _ in range(t):
n, m, k = getVars()
a = getList()
before = min(m - 1, k)
res = 0
if before == 0:
res = foo(a, 0, m)
else:
for i in range(before + 1):
b = a[i : i + n - before]
m1 = foo(b, before, m)
res = max(m1, res)
print(res) | IMPORT ASSIGN 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 RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for loop in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if k < m - 1:
for w in range(k + 1):
x = k - w
nmin = float("inf")
for y in range(m - k):
z = m - k - 1 - y
nmin = min(nmin, max(a[w + y], a[n - 1 - x - z]))
ans = max(nmin, ans)
print(ans)
else:
ans = 0
for i in range(m):
ans = max(ans, a[i], a[n - 1 - i])
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
for ti in range(t):
n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)
a = input().split()
for i in range(n):
a[i] = int(a[i])
if m <= k + 1:
b = a[:m] + a[-m:]
print(str(max(b)))
else:
notcontrol = m - k - 1
allans = []
for j in range(k + 1):
if j == k:
newa = a[j:]
else:
newa = a[j : -k + j]
rang = notcontrol + 1
b = newa[:rang] + newa[-rang:]
allpairs = []
for i in range(rang):
if b[i] > b[i + rang]:
allpairs.append(b[i])
else:
allpairs.append(b[i + rang])
ans = min(allpairs)
allans.append(ans)
print(str(max(allans))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
k = min(k, m - 1)
ans = 0
for l in range(k + 1):
r = k - l
tmp = float("inf")
for l2 in range(m - k):
r2 = m - k - 1 - l2
tmp = min(tmp, max(a[l + l2], a[n - r - r2 - 1]))
ans = max(ans, tmp)
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
k = min(m - 1, k)
ans = 0
for i in range(k + 1):
pos1 = i
pos2 = n - 1 - (k - i)
cur_ans = int(1000000000.0 * 2)
for j in range(m - k):
cur_ans = min(cur_ans, max(a[pos1 + j], a[pos2 - (m - 1 - k - j)]))
ans = max(ans, cur_ans)
print(ans)
t = int(input())
for _ in range(t):
solve() | FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | import sys
def zip_sorted(a, b):
a, b = zip(*sorted(zip(a, b)))
sorted(zip(a, b), key=lambda x: x[1])
return a, b
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
S = lambda: list(map(str, input().split()))
(t,) = I()
for t1 in range(t):
n, m, k = I()
a = I()
a = [0] + a
dp = [0] * m
for i in range(m):
dp[i] = max(a[i + 1], a[n - m + i + 1])
max1 = 0
for i in range(len(dp)):
min1 = dp[i]
for j in range(i, len(dp)):
min1 = min(min1, dp[j])
if i + len(dp) - j - 1 <= k:
min1 = min(min1, dp[j])
max1 = max(max1, min1)
print(max1) | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | from sys import stdin, stdout
def main():
T = int(stdin.readline())
for zzz in range(T):
arr = list(map(int, stdin.readline().split()))
n, m, k = arr
item = list(map(int, stdin.readline().split()))
if m <= k:
k = m - 1
luck = m - k - 1
maxer = 0
for i in range(k + 1):
left = i
right = n - k + i - 1
temp_min = 99999999999
for j in range(luck + 1):
left2 = j
right2 = luck - j
temp_max = max(item[left + left2], item[right - right2])
temp_min = min(temp_min, temp_max)
if maxer == 0:
maxer = temp_min
else:
maxer = max(maxer, temp_min)
stdout.write(str(maxer) + "\n")
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN 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 ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for himself. He then gets out of line, and the next person in line continues the process.
You are standing in the m-th position in the line. Before the process starts, you may choose up to k different people in the line, and persuade them to always take either the first or the last element in the array on their turn (for each person his own choice, not necessarily equal for all people), no matter what the elements themselves are. Once the process starts, you cannot persuade any more people, and you cannot change the choices for the people you already persuaded.
Suppose that you're doing your choices optimally. What is the greatest integer x such that, no matter what are the choices of the friends you didn't choose to control, the element you will take from the array will be greater than or equal to x?
Please note that the friends you don't control may do their choice arbitrarily, and they will not necessarily take the biggest element available.
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains three space-separated integers n, m and k (1 ≤ m ≤ n ≤ 3500, 0 ≤ k ≤ n - 1) — the number of elements in the array, your position in line and the number of people whose choices you can fix.
The second line of each test case contains n positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 3500.
Output
For each test case, print the largest integer x such that you can guarantee to obtain at least x.
Example
Input
4
6 4 2
2 9 2 3 8 5
4 4 1
2 13 60 4
4 1 3
1 2 2 1
2 2 0
1 2
Output
8
4
1
1
Note
In the first test case, an optimal strategy is to force the first person to take the last element and the second person to take the first element.
* the first person will take the last element (5) because he or she was forced by you to take the last element. After this turn the remaining array will be [2, 9, 2, 3, 8];
* the second person will take the first element (2) because he or she was forced by you to take the first element. After this turn the remaining array will be [9, 2, 3, 8];
* if the third person will choose to take the first element (9), at your turn the remaining array will be [2, 3, 8] and you will take 8 (the last element);
* if the third person will choose to take the last element (8), at your turn the remaining array will be [9, 2, 3] and you will take 9 (the first element).
Thus, this strategy guarantees to end up with at least 8. We can prove that there is no strategy that guarantees to end up with at least 9. Hence, the answer is 8.
In the second test case, an optimal strategy is to force the first person to take the first element. Then, in the worst case, both the second and the third person will take the first element: you will end up with 4. | t = int(input())
while t != 0:
n, m, k = map(int, input().split())
list1 = list(map(int, input().split()))
mini = pow(10, 9) + 7
u = 0
list2 = list()
k = min(k, m - 1)
for i in range(m - 1, -1, -1):
p = max(list1[i], list1[len(list1) - 1 - u])
list2.append(p)
u += 1
temp = list()
for i in range(k + 1):
temp.append(min(list2[i : i + m - k]))
print(max(temp))
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
ri, ci = 0, m - 1
while ri < n and ci >= 0:
e = matrix[ri][ci]
if x == e:
return 1
if e < x:
ri += 1
else:
ci -= 1
return 0 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
found = 0
for i in range(m):
found = matrix[i].count(x)
if found != 0:
return 1
return 0 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
for i in range(n):
l = 0
h = m - 1
while l <= h:
mid = (l + h) // 2
if matrix[i][mid] > x:
h = mid - 1
elif matrix[i][mid] < x:
l = mid + 1
else:
return True
return False | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
i = 0
j = m - 1
while i < n and j >= 0:
if matrix[i][j] == x:
return 1
elif matrix[i][j] < x:
i = i + 1
else:
j = j - 1
return 0 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
for i in range(n):
for j in range(m):
if matrix[i][j] == x:
return 1
elif matrix[i][j] > x:
break
return 0 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
row = 0
col = m - 1
while row < n and col < m:
if matrix[row][col] == target:
return True
elif matrix[row][col] > target:
col -= 1
else:
row += 1
return False | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
def bs(arr, s, e, x):
while s <= e:
mid = s + (e - s) // 2
if arr[mid] == x:
return True
elif arr[mid] < x:
s = mid + 1
else:
e = mid - 1
return False
for row in matrix:
if bs(row, 0, len(row) - 1, x):
return True
return False | CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
for i in range(len(matrix)):
if x >= matrix[i][0] and x <= matrix[i][-1]:
def binary(arr, element, start, end):
while start <= end:
mid = (start + end) // 2
if arr[mid] == element:
return mid
elif arr[mid] > element:
end = mid - 1
else:
start = mid + 1
return -1
if binary(matrix[i], x, 0, len(matrix[i]) - 1) != -1:
return 1
return 0 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
res = False
i = 0
j = m - 1
while i < n and j >= 0:
if matrix[i][j] == x:
res = True
break
elif matrix[i][j] < x:
i += 1
else:
j -= 1
return res | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
pn = []
pc = []
for i in range(n):
if matrix[i][0] <= x and matrix[i][m - 1] >= x:
pn.append(i)
for i in range(m):
if matrix[0][i] <= x and matrix[n - 1][i] >= x:
pc.append(i)
for i in pn:
for j in pc:
if matrix[i][j] == x:
return True
return False | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | def solve(l, h, mat, x):
while l < len(mat) and j > 0:
if mat[l][h] == x:
return True
elif mat[l][h] < x:
l += 1
else:
h -= 1
return False
class Solution:
def search(self, matrix, n, m, x):
i, j = 0, m - 1
while matrix[i][j] < x and i < n:
i += 1
if i == n:
return 0
elif solve(i, j, matrix, x):
return 1
return 0 | FUNC_DEF WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
ans = 0
for i in range(n):
if matrix[i][m - 1] >= x:
if matrix[i][m - 1] == x:
ans = 1
break
l = 0
h = n - 1
while l <= h:
mid = (l + h) // 2
if matrix[i][mid] == x:
ans = 1
break
elif matrix[i][mid] < x:
l = mid + 1
elif matrix[i][mid] > x:
h = mid - 1
if ans == 1:
break
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
st_r = n - 1
st_c = 0
while st_c < m and st_r < n:
if x > matrix[st_r][st_c]:
st_c += 1
elif x < matrix[st_r][st_c]:
st_r -= 1
else:
return 1
return 0 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Example 1:
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
Example 2:
Input:
n = 1, m = 6, x = 55
matrix[][] = {{18, 21, 27, 38, 55, 67}}
Output: 1
Explanation: 55 is present in the matrix.
Your Task:
You don't need to read input or print anything. Complete the function search() that takes n, m, x, and matrix[][] as input parameters and returns a boolean value. True if x is present in the matrix and false if it is not present.
Expected Time Complexity: O(N + M)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N, M <= 1000
1 <= mat[][] <= 10^{5}
1 <= X <= 1000 | class Solution:
def search(self, matrix, n, m, x):
l = []
c = 0
for i in range(len(matrix)):
for j in range(len(matrix[0])):
l.append(matrix[i][j])
for i in range(len(l)):
if l[i] == x:
c += 1
if c > 0:
return 1
return 0 | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.