description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1).
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
Input: s1 = "abc", s2 = "xya"
Output: true
Explanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
Input: s1 = "abe", s2 = "acd"
Output: false
Explanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
Example 3:
Input: s1 = "leetcodee", s2 = "interview"
Output: true
Constraints:
s1.length == n
s2.length == n
1 <= n <= 10^5
All strings consist of lowercase English letters.
|
class Solution:
def checkIfCanBreak(self, s1: str, s2: str) -> bool:
perm1 = sorted(list(s1))
perm2 = sorted(list(s2))
zipped = zip(perm1, perm2)
forward = True
backward = True
for x, y in zipped:
if ord(x) > ord(y):
forward = False
if ord(y) > ord(x):
backward = False
return forward or backward
|
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR VAR
|
Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1).
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
Input: s1 = "abc", s2 = "xya"
Output: true
Explanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
Input: s1 = "abe", s2 = "acd"
Output: false
Explanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
Example 3:
Input: s1 = "leetcodee", s2 = "interview"
Output: true
Constraints:
s1.length == n
s2.length == n
1 <= n <= 10^5
All strings consist of lowercase English letters.
|
class Solution:
def checkIfCanBreak(self, s1: str, s2: str) -> bool:
x = "abcdefghijklmnopqrstuvwxyz"
d = defaultdict(int)
for i in range(len(x)):
d[x[i]] = i + 1
a1 = []
a2 = []
for i in range(len(s1)):
a1.append(d[s1[i]])
a2.append(d[s2[i]])
a1.sort()
a2.sort()
c1, c2 = 0, 0
for i in range(len(a1)):
if a1[i] > a2[i]:
c1 += 1
elif a2[i] > a1[i]:
c2 += 1
else:
c1 += 1
c2 += 1
if c1 == len(s1) or c2 == len(s1):
return True
return False
|
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER VAR
|
Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1).
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
Input: s1 = "abc", s2 = "xya"
Output: true
Explanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
Input: s1 = "abe", s2 = "acd"
Output: false
Explanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
Example 3:
Input: s1 = "leetcodee", s2 = "interview"
Output: true
Constraints:
s1.length == n
s2.length == n
1 <= n <= 10^5
All strings consist of lowercase English letters.
|
class Solution:
def checkIfCanBreak(self, s1: str, s2: str) -> bool:
c1 = Counter(s1)
c2 = Counter(s2)
s = set()
diff = 0
for i in range(26):
c = chr(ord("a") + i)
diff += c1[c] - c2[c]
if diff:
s.add(diff > 0)
return len(s) < 2
|
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR BIN_OP VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR
|
Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1).
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
Input: s1 = "abc", s2 = "xya"
Output: true
Explanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
Input: s1 = "abe", s2 = "acd"
Output: false
Explanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
Example 3:
Input: s1 = "leetcodee", s2 = "interview"
Output: true
Constraints:
s1.length == n
s2.length == n
1 <= n <= 10^5
All strings consist of lowercase English letters.
|
class Solution:
def checkIfCanBreak(self, s1: str, s2: str) -> bool:
n = len(s1)
s1 = sorted(s1)
s2 = sorted(s2)
s1_tally = 0
s2_tally = 0
for i in range(n):
if s1[i] >= s2[i]:
s1_tally += 1
if s2[i] >= s1[i]:
s2_tally += 1
return s1_tally == n or s2_tally == n
|
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR VAR
|
Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1).
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
Input: s1 = "abc", s2 = "xya"
Output: true
Explanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
Input: s1 = "abe", s2 = "acd"
Output: false
Explanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
Example 3:
Input: s1 = "leetcodee", s2 = "interview"
Output: true
Constraints:
s1.length == n
s2.length == n
1 <= n <= 10^5
All strings consist of lowercase English letters.
|
class Solution:
def checkIfCanBreak(self, s1: str, s2: str) -> bool:
def ifbreaks(a, b):
a = sorted(a)
b = sorted(b)
for i in range(len(a)):
if a[i] < b[i]:
return False
return True
return ifbreaks(s1, s2) or ifbreaks(s2, s1)
|
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
|
Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1).
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Example 1:
Input: s1 = "abc", s2 = "xya"
Output: true
Explanation: "ayx" is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
Input: s1 = "abe", s2 = "acd"
Output: false
Explanation: All permutations for s1="abe" are: "abe", "aeb", "bae", "bea", "eab" and "eba" and all permutation for s2="acd" are: "acd", "adc", "cad", "cda", "dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
Example 3:
Input: s1 = "leetcodee", s2 = "interview"
Output: true
Constraints:
s1.length == n
s2.length == n
1 <= n <= 10^5
All strings consist of lowercase English letters.
|
class Solution:
def checkIfCanBreak(self, s1: str, s2: str) -> bool:
ar1 = [(0) for i in range(len(s1))]
ar2 = [(0) for i in range(len(s2))]
for i in range(len(s1)):
ar1[i] = ord(s1[i])
ar2[i] = ord(s2[i])
ar1.sort()
ar2.sort()
flag1 = False
flag2 = False
for i in range(len(ar1)):
if ar1[i] - ar2[i] < 0:
flag1 = True
elif ar2[i] - ar1[i] < 0:
flag2 = True
return flag1 == False or flag2 == False
|
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN VAR NUMBER VAR NUMBER VAR
|
You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.
A set of edges is called a matching if no two edges share an endpoint.
A set of vertices is called an independent set if no two vertices are connected with an edge.
Input
The first line contains a single integer T ≥ 1 — the number of graphs you need to process. The description of T graphs follows.
The first line of description of a single graph contains two integers n and m, where 3 ⋅ n is the number of vertices, and m is the number of edges in the graph (1 ≤ n ≤ 10^{5}, 0 ≤ m ≤ 5 ⋅ 10^{5}).
Each of the next m lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ 3 ⋅ n), meaning that there is an edge between vertices v_i and u_i.
It is guaranteed that there are no self-loops and no multiple edges in the graph.
It is guaranteed that the sum of all n over all graphs in a single test does not exceed 10^{5}, and the sum of all m over all graphs in a single test does not exceed 5 ⋅ 10^{5}.
Output
Print your answer for each of the T graphs. Output your answer for a single graph in the following format.
If you found a matching of size n, on the first line print "Matching" (without quotes), and on the second line print n integers — the indices of the edges in the matching. The edges are numbered from 1 to m in the input order.
If you found an independent set of size n, on the first line print "IndSet" (without quotes), and on the second line print n integers — the indices of the vertices in the independent set.
If there is no matching and no independent set of the specified size, print "Impossible" (without quotes).
You can print edges and vertices in any order.
If there are several solutions, print any. In particular, if there are both a matching of size n, and an independent set of size n, then you should print exactly one of such matchings or exactly one of such independent sets.
Example
Input
4
1 2
1 3
1 2
1 2
1 3
1 2
2 5
1 2
3 1
1 4
5 1
1 6
2 15
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6
Output
Matching
2
IndSet
1
IndSet
2 4
Matching
1 15
Note
The first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.
The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5: 2 3 4 5 6. However such answer is not correct, because you are asked to find an independent set (or matching) of size exactly n.
The fourth graph does not have an independent set of size 2, but there is a matching of size 2.
|
from sys import stdin, stdout
T = int(stdin.readline())
ver = set()
for _ in range(T):
ver.clear()
n, m = map(int, stdin.readline().split())
n *= 3
edge = []
for __ in range(m):
u, v = map(int, stdin.readline().split())
if u not in ver and v not in ver:
edge.append(__ + 1)
ver.add(u)
ver.add(v)
if len(edge) == n // 3:
print("Matching")
print(*edge[: n // 3])
for x in range(__ + 1, m):
stdin.readline()
break
if len(edge) < n // 3:
asd = []
for x in range(1, n + 1):
if x not in ver:
asd.append(x)
if len(asd) == n // 3:
print("IndSet")
print(*asd[: n // 3])
break
if len(asd) < n // 3:
stdout.write("Impossible\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
n, x = [int(x) for x in input().split()]
l_ind = [[] for i in range(200000)]
r_ind = [[] for i in range(200000)]
for i in range(n):
l, r, c = [int(x) for x in input().split()]
if r - l + 1 <= x:
l_ind[l - 1].append((l, r, c))
r_ind[r - 1].append((l, r, c))
ans = None
bestCost = [None for i in range(x + 1)]
for vl, vr in zip(l_ind, r_ind):
for l, r, c in vl:
cur_len = r - l + 1
if bestCost[x - cur_len]:
if ans:
ans = min(ans, c + bestCost[x - cur_len])
else:
ans = c + bestCost[x - cur_len]
for l, r, c in vr:
cur_len = r - l + 1
if bestCost[cur_len]:
bestCost[cur_len] = min(bestCost[cur_len], c)
else:
bestCost[cur_len] = c
if ans == None:
print(-1)
else:
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
n, x = list(map(int, input().split()))
V = []
for i in range(x + 1):
V.append([])
for i in range(n):
l, r, c = list(map(int, input().split()))
if r - l + 1 <= x:
V[r - l + 1].append([l, r, c])
for i in range(x + 1):
V[i] = sorted(V[i])
ans = int(3000000000.0 + 7)
for i in range(x + 1):
mn = int(3000000000.0 + 7)
p = 0
k = 0
for j in range(len(V[i])):
while k != len(V[x - i]) and V[i][j][0] > V[x - i][k][1]:
mn = min(mn, V[x - i][k][2])
k = k + 1
ans = min(ans, mn + V[i][j][2])
if ans == int(3000000000.0 + 7):
print(-1)
else:
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER LIST VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
import sys
def main():
n, x = map(int, sys.stdin.readline().split())
al = []
starts = []
finishes = []
y = [(-1) for i in range(200002)]
for i in range(n):
a, b, c = map(int, sys.stdin.readline().split())
al.append((a, b, c))
starts.append((a, i))
finishes.append((b, i))
finishes = sorted(finishes, key=lambda x: x[0])
starts = sorted(starts, key=lambda x: x[0])
j = 0
res = 3 * 10**9
for i in range(n):
while j < n and starts[j][0] <= finishes[i][0]:
c = starts[j][1]
h = al[c][1] - al[c][0] + 1
cost = al[c][2]
if y[x - h] != -1 and y[x - h] + cost < res:
res = y[x - h] + cost
j += 1
c = finishes[i][1]
h = al[c][1] - al[c][0] + 1
cost = al[c][2]
if y[h] == -1 or y[h] > cost:
y[h] = cost
if res == 3 * 10**9:
print(-1)
else:
print(res)
main()
|
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
Q = map
E = input
B = range
W = enumerate
o = len
P = min
q = print
def U():
return Q(int, E().split())
n, x = U()
s = [[] for i in B(x - 1)]
for d in B(n):
l, r, c = U()
if r - l < x - 1:
s[r - l] += [[l, c]]
for t in s:
t.sort(key=lambda q: q[0])
m = 3000000000.0
for d, t in W(s):
D = x - 2 - d
i, T = 0, s[D]
M = 3000000000.0
for l, c in t:
while i < o(T) and l > T[i][0] + D:
M = P(M, T[i][1])
i += 1
m = P(m, c + M)
q(-1 if m == 3000000000.0 else m)
|
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR LIST LIST VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
from sys import stdin, stdout
n, x = map(int, stdin.readline().split())
length = [[] for i in range(x + 1)]
mins = [[] for i in range(x + 1)]
challengers = []
for i in range(n):
l, r, v = map(int, stdin.readline().split())
if r - l < x:
length[r - l + 1].append((l, v))
for i in range(1, x + 1):
if not len(length[i]):
continue
else:
length[i].sort()
mn = length[i][-1][-1]
mins[i].append(mn)
for j in range(len(length[i]) - 2, -1, -1):
mn = min(mn, length[i][j][-1])
mins[i].append(mn)
mins[i] = mins[i][::-1]
INF = float("inf")
ans = INF
for i in range(1, x + 1):
if not len(length[i]) or not len(length[x - i]):
continue
for j in range(len(length[i])):
pos, v = length[i][j]
l, r = -1, len(length[x - i])
while r - l > 1:
m = (r + l) // 2
if length[x - i][m][0] > pos + i - 1:
r = m
else:
l = m
if r != len(length[x - i]):
ans = min(ans, v + mins[x - i][r])
if ans == INF:
stdout.write("-1")
else:
stdout.write(str(ans))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
n, x = map(int, input().split())
arr = list(tuple(map(int, input().split())) for _ in range(n))
arr_first = arr[:]
arr_second = arr[:]
arr_first.sort(key=lambda i: i[0])
arr_second.sort(key=lambda i: i[1])
d, idx, res = {}, 0, int(10**18)
for l, r, c in arr_second:
while idx < n and r >= arr_first[idx][0]:
k = x - (arr_first[idx][1] - arr_first[idx][0] + 1)
if k in d:
res = min(res, d[k] + arr_first[idx][2])
idx += 1
tmp = r - l + 1
d[tmp] = c if tmp not in d else min(d[tmp], c)
print(-1 if res == int(10**18) else res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR DICT NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
def main():
n, x = map(int, input().split())
vouchers = [False] * x
for _ in range(n):
lo, hi, cost = map(int, input().split())
w = hi - lo
if w < x:
l = vouchers[w]
if l:
l.append((lo, cost))
else:
vouchers[w] = [(lo, cost)]
best = inf = 1 << 31
x -= 2
if not x & 1 and vouchers[x // 2]:
lh, h = vouchers[x // 2], None
for f in (lh.sort, lh.reverse):
l = h
f()
h, b = [], inf
for lo, cost in lh:
if b > cost:
b = cost
h.append((lo, b))
b, v = h.pop()
for a, u in l:
a += w
while a >= b and h:
b, v = h.pop()
if a < b and best > u + v:
best = u + v
for w, l, h in zip(range(x), vouchers, vouchers[x : x // 2 : -1]):
if l and h:
m = []
for lh in (l, h):
for f in (lh.sort, lh.reverse):
f()
t, b = [], inf
for lo, cost in lh:
if b > cost:
b = cost
t.append((lo, b))
m.append(t)
for l, h in ((m[0], m[3]), (m[2], m[1])):
b, v = h.pop()
for a, u in l:
a += w
while a >= b and h:
b, v = h.pop()
if a < b and best > u + v:
best = u + v
w = x - w
print(best if best < inf else -1)
main()
|
FUNC_DEF ASSIGN VAR 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 VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NONE FOR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR VAR VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR VAR VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
import sys
input = sys.stdin.readline
n, x = map(int, input().split())
lrc = [tuple(map(int, input().split())) for _ in range(n)]
lrc.sort(key=lambda k: k[0])
lrc2 = lrc[:]
lrc.sort(key=lambda k: k[1])
d = {}
idx = 0
ans = 10**18
for l, r, c in lrc:
while idx < n and r >= lrc2[idx][0]:
k = x - (lrc2[idx][1] - lrc2[idx][0] + 1)
if k in d:
ans = min(ans, d[k] + lrc2[idx][2])
idx += 1
if r - l + 1 not in d:
d[r - l + 1] = c
else:
d[r - l + 1] = min(d[r - l + 1], c)
if ans == 10**18:
print(-1)
else:
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN 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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
import sys
input = sys.stdin.readline
n, x = map(int, input().split())
vo = [list(map(int, input().split())) for i in range(n)]
d = [[] for i in range(x + 1)]
for l, r, c in vo:
if r - l + 1 <= x:
d[r - l + 1].append([l, c])
mins = [[] for i in range(x + 1)]
for i in range(1, x + 1):
if len(d[i]) == 0:
continue
d[i].sort()
cum_min_cost = 10**18
for j in range(len(d[i]))[::-1]:
cum_min_cost = min(cum_min_cost, d[i][j][1])
mins[i].append(cum_min_cost)
mins[i] = mins[i][::-1]
ans = 10**18
for i in range(1, x + 1):
if len(d[i]) == 0 or len(d[x - i]) == 0:
continue
for j in range(len(d[i])):
pos, v = d[i][j]
l = -1
r = len(d[x - i])
while r - l > 1:
mid = (r + l) // 2
if d[x - i][mid][0] > i + pos - 1:
r = mid
else:
l = mid
if r < len(d[x - i]):
ans = min(ans, mins[x - i][r] + v)
if ans == 10**18:
print(-1)
else:
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN 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 VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER LIST VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l_{i}, r_{i}, cost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r_{i} - l_{i} + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r_{i} < l_{j} or r_{j} < l_{i}.
Help Leha to choose the necessary vouchers!
-----Input-----
The first line contains two integers n and x (2 ≤ n, x ≤ 2·10^5) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l_{i}, r_{i} and cost_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 2·10^5, 1 ≤ cost_{i} ≤ 10^9) — description of the voucher.
-----Output-----
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
-----Examples-----
Input
4 5
1 3 4
1 2 5
5 6 1
1 2 4
Output
5
Input
3 2
4 6 3
2 4 1
3 5 4
Output
-1
-----Note-----
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
|
n, x = map(int, input().split())
INF = float("inf")
bestScore = [INF] * x
q = []
for i in range(n):
l, r, c = map(int, input().split())
q.append((l, -1, r, c))
q.append((r, 1, l, c))
q = sorted(q)
ans = INF
for i in range(len(q)):
type = q[i][1]
if type == -1:
curLen = q[i][2] - q[i][0] + 1
if x - curLen >= 0:
ans = min(ans, q[i][3] + bestScore[x - curLen])
else:
curLen = q[i][0] - q[i][2] + 1
if curLen < x:
bestScore[curLen] = min(bestScore[curLen], q[i][3])
if ans >= INF:
print(-1)
else:
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l[:n]
l = l[n:]
print(l[n // 2])
for i in range(n):
print(m[i], l[i], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
def solve(arr):
lst = sorted(arr)
n = len(arr) // 2
b = []
final = []
for i in range(n):
b.append(max(lst[i], lst[i + n]))
final.append(lst[i])
final.append(lst[i + n])
print(b[len(b) // 2])
print(" ".join(map(str, final)))
t = int(input())
while t:
n = int(input())
arr = list(map(int, input().split()))
solve(arr)
t -= 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
x = a[(n - 1) // 2]
a = sorted(a)
print(x)
for i in range(n):
print(a[i], a[n + i], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
for _ in range(t):
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
print(arr[(3 * n - 1) // 2])
for i in range(n):
print(arr[i], arr[n + i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
T = int(input())
for _ in range(0, T):
N = int(input())
a = list(map(int, input().split(" ")))
a = sorted(a)
print(a[(3 * N + 1) // 2 - 1])
print(*[y for x in zip(a[0:N], a[N : 2 * N]) for y in x if y is not None])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR NONE
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
median = 0
if n % 2 == 0:
median = a[n + (n // 2 - 1)]
else:
median = a[n + n // 2]
ans = []
for i in range(n):
ans.append(a[i])
ans.append(a[-i - 1])
print(median)
print(*ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = A[N:]
C = A[:N]
X = []
p = B[N // 2]
print(p)
for i, j in zip(B, C):
X.append(i)
X.append(j)
print(*X)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
def quicksort(myList, start, end):
if start < end:
pivot = partition(myList, start, end)
quicksort(myList, start, pivot - 1)
quicksort(myList, pivot + 1, end)
return myList
def partition(myList, start, end):
pivot = myList[start]
left = start + 1
right = end
done = False
while not done:
while left <= right and myList[left] <= pivot:
left = left + 1
while myList[right] >= pivot and right >= left:
right = right - 1
if right < left:
done = True
else:
temp = myList[left]
myList[left] = myList[right]
myList[right] = temp
temp = myList[start]
myList[start] = myList[right]
myList[right] = temp
return right
T = int(input())
for j in range(T):
n = int(input())
A = [int(n) for n in input().split()]
C = quicksort(A, 0, len(A) - 1)
median = C[2 * n - (n + 1) // 2]
for i in range((n - 1) // 2):
d = C[2 * i + 1]
C[2 * i + 1] = C[2 * n - 2 * i - 1]
C[2 * n - 2 * i - 1] = d
print(median)
print(*C)
|
FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
T = int(input())
for t in range(T):
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-((N + 1) // 2)])
B = []
N *= 2
for i in range(N // 2):
B.extend([str(A[i]), str(A[i + N // 2])])
print(" ".join(B))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
from sys import stdin
def permute_max_median(A):
A.sort()
median = A[len(A) // 2 + len(A) // 4]
for i in range(len(A) // 2):
A[i * 2 + 1], A[len(A) // 2 + i] = A[len(A) // 2 + i], A[i * 2 + 1]
return median
def main():
from sys import stdin
T = int(stdin.readline())
for t in range(T):
N = int(stdin.readline())
A = list(int(a) for a in stdin.readline().split())
assert len(A) == N * 2
print(permute_max_median(A))
print(*A)
main()
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
for _ in range(t):
n = int(input())
arr = sorted(list(map(int, input().split())))
a = arr[n : 2 * n]
print(a[n // 2])
for i in range(n):
print(arr[i], arr[n + i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = []
for i in range(n):
b.append(max(a[i], a[len(a) - 1 - i]))
if n % 2 == 1:
print(b[(n - 1) // 2])
else:
print(max(b[len(b) // 2 - 1], b[len(b) // 2]))
for i in range(n):
print(str(a[i]) + " " + str(b[i]), end=" ")
print("")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR 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 FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
A.sort()
up = A[N:]
down = A[:N]
print(up[N >> 1])
A = []
for x, y in zip(down, up):
A.append(x)
A.append(y)
print(" ".join(map(str, A)))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for tc in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort()
a = l[:n]
b = l[n : 2 * n]
m = []
for i in range(n):
m.append(a[i])
m.append(b[n - 1 - i])
print(l[3 * n // 2])
for i in m:
print(i, end=" ")
print("\n")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
while t:
t = t - 1
n = int(input())
b = []
a = list(map(int, input().split()))
a.sort()
a1 = [-1] * (2 * n)
k1 = 2 * n - 1
k2 = 0
for i in range(0, len(a)):
if i % 2 == 0:
a1[i] = a[k1]
k1 -= 1
else:
a1[i] = a[k2]
k2 += 1
for i in range(0, len(a), 2):
b.append(a1[i])
print(b[len(b) // 2])
for i in range(len(a)):
print(a1[i], sep=" ", end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
tests = int(input())
for i in range(tests):
length = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = []
for j in range(length):
ans.append(arr[j])
ans.append(arr[-j - 1])
median_pos = length + length // 2
print(arr[median_pos])
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
N = int(input())
st = input().split()
A = []
for x in st:
A.append(int(x))
A.sort()
p = N + N // 2
M = A[p]
st = ""
for k in range(N):
st += str(A[k]) + " " + str(A[k + N]) + " "
print(M)
print(st)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
cases = int(input())
j = 0
while j < cases:
j += 1
n = int(input())
mid = int((n - 1) / 2)
a_raw = input().split()
a = [int(x) for x in a_raw]
a.sort()
b = a[1::2]
for i in range(mid):
a[2 * i], a[2 * (n - i - 1)] = a[2 * (n - i - 1)], a[2 * i]
b[i] = max(a[2 * i], b[i])
b.sort()
median = b[mid]
a_raw = [str(x) for x in a]
print(median)
print(" ".join(a_raw))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(a[2 * n - 1 - (n - 1) // 2])
B = []
for i in range(n):
B.append(str(a[i]))
B.append(str(a[i + n]))
print(" ".join(B))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
while t > 0:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = a[: len(a) // 2]
c = a[len(a) // 2 :]
p = [0] * len(a)
j = 0
k = 0
for i in range(len(p)):
if i % 2 == 0:
p[i] = b[j]
j += 1
else:
p[i] = c[k]
k += 1
med = p[len(p) // 2]
print(med)
for x in p:
print(x, end=" ")
print()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for T in range(int(input())):
N = int(input())
nums = sorted(list(map(int, input().split())))
result = [0] * (2 * N)
list_pointer = 2 * N - 1
for index in range(list_pointer, -1, -2):
result[index] = nums[list_pointer]
list_pointer -= 1
store_pointer = 0
for index in range(list_pointer + 1):
result[store_pointer] = nums[index]
store_pointer += 2
print(max(result[N], result[N - 1]))
print(*result)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
n = int(input())
for _ in range(n):
p = int(input())
t = [int(j) for j in input().split()]
t.sort()
ls = t[p : 2 * p]
d = int((p - 1) / 2)
print(ls[d])
q = list()
for i in range(p):
q.append(t[i])
q.append(ls[i])
print(*q)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l[n:]
m = m[n // 2]
print(m)
l2 = []
for i in range(n):
l2.append(l[i])
l2.append(l[2 * n - i - 1])
print(*l2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for i in range(int(input())):
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
l2 = l[: len(l) // 2]
l1 = l[len(l) // 2 :]
print(l1[len(l1) // 2])
for i in range(n):
print(l2[i], l1[i], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
a, b = a[: n // 2 * 2], a[n // 2 * 2 :]
c = []
for i in range(len(b) // 2):
c.append(b[i])
c.append(b[i + n // 2 + 1])
print(c[1])
print(" ".join(str(x) for x in a + c))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
x = [0] * (2 * n)
c = 0
for j in range(2 * n - 1, -1, -2):
x[j] = l[c]
c += 1
for j in range(2 * n - 2, -1, -2):
x[j] = l[c]
c += 1
c = n // 2
ans = max(x[2 * c], x[2 * c + 1])
print(ans)
print(*x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
x = int(input())
for i in range(0, x):
y = int(input())
q = list(map(int, input().strip().split(" ")))
q.sort()
m = q[y : 2 * y]
ans = m[y // 2]
print(ans)
for i in range(0, y, 2):
t = q[i]
q[i] = q[y]
q[y] = t
y = y + 2
for u in range(0, len(q) - 1):
print(q[u], end=" ")
print(q[u + 1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
for k in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
if n == 1:
print(max(a[0], a[1]))
for i in range(len(a)):
print(a[i], end=" ")
print()
else:
a.sort()
b = []
j = 0
for i in range(n):
b.append(a[i])
b.append(a[2 * n - i - 1])
print(max(b[n], b[n + 1]))
for i in range(len(a)):
print(b[i], end=" ")
print()
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
def CreateDic(nums):
dic = dict()
for i in nums:
if not i in dic:
dic[i] = 1
else:
dic[i] += 1
return dic
for _ in range(int(input())):
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
numsA = []
for i in range(1, n + 1):
numsA.append(nums[i - 1])
numsA.append(nums[i - 1 + n])
numsB = []
for i in range(n, 2 * n):
numsB.append(nums[i])
print(numsB[int(len(numsB) / 2)])
for i in numsA:
print(i, end=" ")
print()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
n = int(input())
while n:
n -= 1
N = int(input())
l = [int(x) for x in input().split()]
b = []
l.sort()
for i in range(N):
b.append(l[i])
b.append(l[N + i])
print(b[N])
print(*b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for i in range(int(input())):
n = int(input())
x = input()
x = list(map(int, x.split()))
x.sort()
y = x[n:]
print(y[n // 2])
i = 0
while i < n:
print(x[i], x[n + i], end=" ")
i += 1
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
tc = int(input())
for i in range(tc):
b = []
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
k = 2 * n
if n == 1:
print(a[1])
print(" ".join(map(str, a)))
else:
x = 1
y = n
while x < y:
tmp = a[x]
a[x] = a[y]
a[y] = tmp
x += 2
y += 1
for j in range(0, k, 2):
b.append(a[j + 1])
print(b[n // 2])
print(" ".join(map(str, a)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
n = int(input())
while n > 0:
c = int(input())
a = list(map(int, input().split()))
b = sorted(a)
lb = len(b)
mid = int(c)
median = int(2 * c - (c + 1) / 2)
print(b[median])
b[mid], b[median] = b[median], b[mid]
for i in range(c - 1):
if i % 2 != 0:
b[i - 1], b[lb - i - 1] = b[lb - i - 1], b[i - 1]
for r in b:
print(r, end=" ")
print()
n -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
def cal():
T = int(input())
for _ in range(T):
n = int(input())
A1 = list(map(int, input().split()))
A = sorted(A1)
if n % 2 == 1:
print(A[n + int(n / 2)])
else:
print(max(A[n + int(n / 2)], A[n + int(n / 2) - 1]))
for i in range(n):
print(A[i], A[n + i], end=" ")
print()
cal()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
test = input()
test = int(test)
for j in range(0, test):
n = input()
n = int(n)
list2 = []
list3 = []
list4 = []
list2 = list(map(int, input().strip().split(" ")))
list2.sort()
print(list2[len(list2) - n // 2 - 1])
j = len(list2) - 1
for i in range(0, n, 2):
list2[i], list2[j] = list2[j], list2[i]
j -= 1
for i in range(0, len(list2) - 1):
print(list2[i], end=" ")
print(list2[i + 1])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
while t:
n = int(input())
x = n
y = n + int(n / 2)
l = list(map(int, input().split()))
p = []
q = []
l.sort()
z = l[y]
for i in range(x, 2 * n):
p.append(l[i])
for i in range(0, x):
q.append(l[i])
q.append(p[i])
print(z)
for i in q:
print(i, end=" ")
print()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
while t:
n = int(input())
l = list(map(int, input().split()))
l.sort()
l2 = l[n : 2 * n]
mid = n // 2
print(l2[mid])
for i in range(0, n):
print(l[i], end=" ")
print(l2[i], end=" ")
print("\n", end="")
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
while t > 0:
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
output = []
a = l[:n]
b = l[n:]
list(output.extend(i) for i in zip(a, b))
alpha = int((n - 1) / 2)
print(b[alpha])
output = " ".join(map(str, output))
print(output)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
for i in range(t):
s = int(input())
arr = list(map(int, input().split()))
arr.sort()
hold = int(s / 2)
print(arr[2 * s - 1 - hold])
for j in range(s):
print(arr[j], arr[2 * s - 1 - j], end=" ", sep=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR STRING STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
a = sorted(list(map(int, input().split())))
mdn = a[n + n // 2]
b = []
for i in range(n):
b.append(a[i])
b.append(a[n + i])
print(mdn)
print(*b)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
import sys
for i in range(int(sys.stdin.readline())):
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
a.sort()
sys.stdout.write(str(a[n:][int((n - 1) / 2)]) + "\n")
for j in range(n):
sys.stdout.write(str(a[j]) + " " + str(a[n + j]) + " ")
sys.stdout.write("\n")
|
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n, a = int(input()), sorted([int(x) for x in input().split()])
c = []
for i in range(n):
c.append(a[i])
c.append(a[n + i])
print(c[2 * (n // 2) + 1])
print(*c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for t in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
sa = sorted(a)
b = []
c = []
for i in range(n, 2 * n):
b.append(sa[i])
for i in range(0, n):
c.append(sa[i])
print(b[n // 2])
for i in range(0, n):
print(c[i], b[i], end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
def compose_list(l_idx, sub_len, r_idx, t_list):
new_list = []
for iterv in range(sub_len):
new_list.append(t_list[l_idx])
l_idx += 1
new_list.append(t_list[r_idx])
r_idx += 1
return new_list
t_num = int(input())
for t_iter in range(t_num):
t_len = int(input())
twice_idx = 2 * t_len
a_list = [-1]
a_list = a_list + [int(xvar) for xvar in input().split(" ")]
a_list.sort()
a_list = [-1] + compose_list(1, t_len, t_len + 1, a_list)
print(a_list[t_len + 1])
print(*a_list[1:], sep=" ")
|
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
t = int(input())
while t > 0:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
b, c = l[0 : len(l) // 2], l[len(l) // 2 :]
d = []
for i in range(len(b)):
d.append(b[i])
d.append(c[i])
print(b[len(b) // 2])
for i in range(len(d)):
print(d[i], end=" ")
print("")
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for t in range(int(input())):
n = 2 * int(input())
A = list(map(int, input().split()))
A = list(sorted(A))
Alow = A[: n // 2]
Ahigh = A[n // 2 :]
median = Ahigh[n // 4]
B = []
for i in range(n // 2):
B.append(Alow[i])
B.append(Ahigh[i])
print(median)
print(*B)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
for _ in range(int(input())):
n = int(input())
Ai = list(map(int, input().split()))
Ai.sort()
Aip = []
for i in range(n):
Aip.extend([Ai[i], Ai[n + i]])
print(Aip[n])
print(*Aip)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given an array A of size 2 * N consisting of positive integers, where N is an odd number. You can construct an array B from A as follows, B[i] = max(A[2 * i - 1], A[2 * i]), i.e. B array contains the maximum of adjacent pairs of array A. Assume that we use 1-based indexing throughout the problem.
You want to maximize the median of the array B. For achieving that, you are allowed to permute the entries of A. Find out the maximum median of corresponding B array that you can get. Also, find out any permutation for which this maximum is achieved.
------ Note ------
Median of an array of size n, where n is odd, is the middle element of the array when it is sorted in non-decreasing order. Note that n being odd, the middle element will be unique, i.e. at index (n+1) / 2.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer N.
The second line of each test case contains 2 * N space separated integers denoting array A.
------ Output ------
For each test case, output two lines.
The first of which should contain an integer corresponding to maximum value of the median of array B that you can get.
In the second line, print 2 * N integers in a single line denoting any permutation of A for which the maximum value of median of array B is achieved.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 50000$
$1 ≤ A_{i} ≤ 2 * N$
------ Subtasks ------
$Subtask #1 (25 points) : 1 ≤ N ≤ 3$
$Subtask #2 (75 points) : original constraints$
----- Sample Input 1 ------
3
1
1 2
3
1 2 3 4 5 6
3
1 3 3 3 2 2
----- Sample Output 1 ------
2
1 2
5
1 3 2 5 4 6
3
1 3 3 3 2 2
----- explanation 1 ------
Example case 1. There are only two possible permutations of A, for both of those B will be 2. The median of B is 2.
Example case 2. For following permutation of A: 1 3 2 5 4 6, the corresponding B will be: 3 5 6, whose median is 5, which is the maximum that you can achieve.
Example case 3. For A: 1 3 3 3 2 2, the corresponding B will be: 3, 3, 2. Its
median is 3, which is maximum that you can achieve.
|
def partition(arr, low, high):
i = low - 1
pivot = arr[high]
for j in range(low, high):
if arr[j] <= pivot:
i = i + 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickSort(arr, low, high):
if low < high:
pi = partition(arr, low, high)
quickSort(arr, low, pi - 1)
quickSort(arr, pi + 1, high)
for _ in range(int(input())):
N = int(input())
arr = list(map(int, input().strip().split()))
quickSort(arr, 0, len(arr) - 1)
s1 = str(arr[0])
print(arr[N // 2 + N])
for i in range(N):
print(arr[i], arr[N + i], end=" ")
print()
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR
|
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
|
import sys
input = sys.stdin.readline
N = int(200000.0 + 1)
n, k, s, t = map(int, input().split())
car = [list(map(int, input().split())) for _ in range(n)]
g = sorted(list(map(int, input().split()))) + [0]
g[k] = s - g[k - 1]
for i in range(k - 1, 0, -1):
g[i] -= g[i - 1]
def is_valid(g, k, v, t):
need = 0
for i in range(k + 1):
need += max(g[i], 3 * g[i] - v)
return need <= t
def binary_search(g, k):
l, r = max(g), int(2000000000.0)
while l < r:
v = l + (r - l) // 2
if is_valid(g, k, v, t):
r = v
else:
l = v + 1
return l
l = binary_search(g, k)
res = int(2000000000.0)
for i in range(n):
if car[i][1] >= l:
res = min(res, car[i][0])
print(-1 if res == int(2000000000.0) else res)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR
|
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
|
import sys
def roadToCinema(V, S, T, stations):
m = len(stations)
t = 0
stations.append(S)
prev = 0
for cur in stations:
dis = cur - prev
if dis > V:
return False
else:
t += max(dis * 3 - V, dis)
if t > T:
return False
prev = cur
return True
def binSearch(S, T, stations):
l = 0
r = S * 2
if T < S:
return float("inf")
while l + 1 < r:
m = l + (r - l) // 2
if roadToCinema(m, S, T, stations) == True:
r = m
else:
l = m
return r
line = sys.stdin.readline()
[N, M, S, T] = list(map(int, line.split(" ")))
aircrafts = []
for i in range(N):
[c, v] = list(map(int, sys.stdin.readline().split(" ")))
aircrafts.append([c, v])
stations = list(map(int, sys.stdin.readline().split(" ")))
stations.sort()
minVolume = binSearch(S, T, stations)
if minVolume == float("inf"):
print(-1)
else:
res = float("inf")
for i in range(N):
if aircrafts[i][1] >= minVolume:
res = min(res, aircrafts[i][0])
if res == float("inf"):
print(-1)
else:
print(res)
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR STRING WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split(" "))
def met(x, n, k):
k -= 1
r = n - k
k = min(k, x - 1)
r = min(r, x)
return (2 * x - k - 1) * k // 2 + (2 * x - r + 1) * r // 2
def busqueda_binaria(l, r):
if l > r:
return r
mitad = (l + r) // 2
if met(mitad, n, k) <= m:
return busqueda_binaria(mitad + 1, r)
return busqueda_binaria(l, mitad - 1)
sol = 1
m = m - n
sol += busqueda_binaria(0, 1000000001)
print(sol)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
def quiero(s):
ne = s + (s - 1) * s
if s > k:
d = s - k
ne -= d * (d + 1) // 2
if s + k - 1 > n:
d = s + k - n - 1
ne -= d * (d + 1) // 2
return ne
lo, hi = 0, m
while hi > lo:
mid = (hi + lo + 1) // 2
if n + quiero(mid) <= m:
lo = mid
else:
hi = mid - 1
print(lo + 1)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
l = 0
r = int(1000000000000.0)
while r - l > 1:
x = (r + l) // 2
if x >= k:
sum1 = x * (k - 1) - k * (k - 1) // 2
else:
t = x - 1
sum1 = t * x - t * (t + 1) // 2 + k - 1 - t
k1 = n - k + 1
if x >= k1:
sum2 = x * (k1 - 1) - k1 * (k1 - 1) // 2
else:
t = x - 1
sum2 = t * x - t * (t + 1) // 2 + k1 - 1 - t
if sum1 + sum2 + x <= m:
l = x
else:
r = x
print(l)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, k, my = map(int, input().split())
def distribute(l, r, c):
if l > r:
return 0
x = r - l + 1
if x > c:
x = c
return x * (x + 1) // 2 + (c - x) * x
def givable(cc):
return distribute(1, my - 1, cc - 1) + distribute(my + 1, n, cc - 1) + cc <= k
Ans = 1
k = k - n
high, low, mid, additional = k, 0, -1, 0
while low <= high:
mid = (high + low) // 2
if givable(mid) == True:
additional = mid
low = mid + 1
else:
high = mid - 1
print(Ans + additional)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = list(map(int, input().split(" ")))
extra = m - n
maxi = 1
if n == 1:
print(m)
elif n == 2:
if m % 2 == 0:
print(m // 2)
else:
print(m // 2 + 1)
else:
for i in range(extra):
stepPillows = 1 + min(k - 1, i) + min(n - k, i)
if extra >= stepPillows:
extra -= stepPillows
maxi += 1
else:
break
print(maxi)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def check(x):
s = 0
if x - 1 <= n - k:
sr = x * (x - 1) // 2 + n - k - x + 1
else:
sr = x * (x - 1) // 2 - (x - (n - k + 1)) * (x - (n - k + 1) + 1) // 2
if x - 1 <= k - 1:
sl = x * (x - 1) // 2 + k - x
else:
sl = x * (x - 1) // 2 - (x - (k - 1)) * (x - (k - 1) - 1) // 2
s = sl + sr + x
if s <= m:
return True
else:
return False
n, m, k = list(map(int, input().split()))
st = 1
ed = m
while st <= ed:
md = (st + ed) // 2
if check(md):
if md == m or not check(md + 1):
print(md)
break
else:
st = md + 1
else:
ed = md - 1
|
FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
m -= n
k -= 1
frodo = 1
left = right = k
while True:
needed = right - left + 1
if m >= needed:
frodo += 1
m -= needed
left = max(0, left - 1)
right = min(n - 1, right + 1)
if left == 0 and right == n - 1:
frodo += m // n
break
else:
break
print(frodo)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
R = lambda: map(int, input().split())
n, p, k = R()
l, r = 1, p
while l < r:
m = (l + r + 1) // 2
cl = (m + max(1, m - k + 1)) * min(k, m) // 2 + max(k - m, 0)
cr = (m + max(1, m - (n - k))) * min(n - k + 1, m) // 2 + max(n - k + 1 - m, 0)
if cl + cr - m <= p:
l = m
else:
r = m - 1
print(l)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = [int(x) for x in input().split()]
if n == 1:
print(m)
else:
m -= n
extra = 0
while m > min(k - 1, extra) + min(n - k, extra):
m -= min(k - 1, extra) + min(n - k, extra) + 1
extra += 1
print(1 + extra)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def is_ok(x, y):
if y > x - 1:
val = ((x - 1) * x >> 1) + y - (x - 1)
else:
val = y * (x - 1 + x - y) >> 1
return val
hobbits, pillows, k = [int(x) for x in input().split()]
l = 1
r = pillows
while l <= r:
m = l + r >> 1
valor = is_ok(m, k - 1) + is_ok(m, hobbits - k) + m
if valor <= pillows:
l = m + 1
else:
r = m - 1
print(l - 1)
|
FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
k1 = n - k + 1
def case(x):
res = x
if k == x:
res += x * (x - 1) // 2
elif k > x:
res += x * (x - 1) // 2 + k - x
else:
res += x * (x - 1) // 2 - (x - k) * (x - k + 1) // 2
if k1 == x:
res += x * (x - 1) // 2
elif k1 > x:
res += x * (x - 1) // 2 + k1 - x
else:
res += x * (x - 1) // 2 - (x - k1) * (x - k1 + 1) // 2
return res
i, j = 0, m
while i + 1 < j:
mid = (i + j) // 2
if case(mid) <= m:
i = mid
else:
j = mid
if n == 1:
print(m)
else:
print(i)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
l, r = int(0), m
while l + 1 < r:
mid = (l + r) // 2
lpos = max(1, k - mid + 1)
lcnt = (mid - (k - lpos) + mid) * (k - lpos + 1) // 2
rpos = min(n, k + mid - 1)
rcnt = (mid - (rpos - k) + mid) * (rpos - k + 1) // 2
if lcnt + rcnt - mid > m - n:
r = mid
else:
l = mid
print(l + 1)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
ans = 1
m -= n
osn = 0
while m > 1:
if osn == max(k - 1, n - k):
break
ans += 1
m -= 1
osnl, osnr = min(k - 1, osn), min(n - k, osn)
osn += 1
m -= osnl + osnr
ans += m // n
print(ans)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
import sys
def check1(l, r, m):
if m == 0:
return l
if l >= r - 1:
return l + 1
mid = int((l + r) // 2)
last = 2 * mid + 1
sr = (1 + last) * (mid + 1) / 2
if m >= sr:
return check1(mid, r, m)
return check1(l, mid, m)
def check2(first, l, r, m):
if l >= r - 1:
return l + 1
mid = int((l + r) // 2)
last = first + mid
sr = (first + last) * (mid + 1) / 2
if m >= sr:
return check2(first, mid, r, m)
return check2(first, l, mid, m)
def main():
n, m, k = map(int, sys.stdin.readline().split())
if n == 1:
print(m)
return
k = k - 1
if k < n / 2:
k = n - k - 1
r = 1
m = m - n
c = n - k - 1
last = 2 * c + 1
s = (1 + last) * (c + 1) / 2
if s > m:
r += check1(0, c, m)
print(r)
return
m = m - s
r += c + 1
first = last + 1
last = n
c = last - first + 1
s = (last + first) * c / 2
if m < first:
print(r)
return
if s > m:
r += check2(first, 0, c - 1, m)
print(r)
return
m = m - s
r += c
rest = int(m / n)
r += rest
print(r)
main()
|
IMPORT FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = list(map(int, input().split()))
l, r = 1, 10**9 + 1
def ok(p):
rs = 0
if k >= p:
rs += p * (p + 1) // 2
rs += k - p
else:
rs += p * (p + 1) // 2
f = p - k
rs -= f * (f + 1) // 2
if p - 1 <= n - k:
rs += p * (p - 1) // 2
rs += n - k - p + 1
else:
rs += p * (p - 1) // 2
f = p - 1 - (n - k)
rs -= f * (f + 1) // 2
return rs <= m
while r - l > 1:
mid = (l + r) // 2
if ok(mid):
l = mid
else:
r = mid
print(l)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def bin_search(l, r, func):
while l < r:
c = (l + r) // 2
val = func(c)
if l + 1 == r:
if func(r):
return r
if func(l):
return l
if val:
l = c
else:
r = c - 1
if l == r:
return l
else:
return 1
def solve(n, m, k):
hr, hl = k - 1, n - k
s_one_n = lambda n: n * (1.0 + n) / 2.0
def s_n_m(n, m):
return (m - n + 1) * (n + m) / 2.0
def snm(n, m):
return s_one_n(max(n, m)) - s_one_n(min(n, m) - 1)
def calc_side(ft, hs):
if hs == 0:
return 0
return s_n_m(max(1, ft - hs), ft - 1) + max(0, hs - ft + 1)
f = lambda x: calc_side(x, hl) + calc_side(x, hr) + x <= m
print(bin_search(1, m * 3, f))
n, m, k = map(int, input().split(" "))
solve(n, m, k)
|
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR RETURN VAR IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
[n, m, k] = list(map(int, input().split()))
m -= n
lo = 0
hi = m
while lo < hi:
x = (lo + hi + 1) // 2
need = x * x
if k < x:
need -= (x - k) * (x - k + 1) // 2
if k + x > n:
need -= (k + x - 1 - n) * (k + x - n) // 2
if need <= m:
lo = x
else:
hi = x - 1
print(lo + 1)
|
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
m -= n
def valid(x):
a = min(k - 1, x - 1)
b = min(n - k, x - 1)
s1 = a * (x - 1 + x - a) // 2
s2 = b * (x - 1 + x - b) // 2
return s1 + s2 + x <= m
l, r = 0, 1 << 62
while r > l + 1:
mid = l + r >> 1
if valid(mid):
l = mid
else:
r = mid
print(l + 1)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
m -= n
soon = False
summ = 0
g = 1
i = 0
for i in range(1, 1 + min(n - k, k - 1)):
summ += g
g += 2
if summ > m:
soon = True
break
if not soon:
for i in range(1 + min(n - k, k - 1), 1 + max(n - k, k - 1)):
summ += g
g += 1
if summ > m:
soon = True
break
print(i if soon else 1 + i + (m - summ) // n)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = map(int, input().split())
m -= n
l, u, x = k, k, 1
while m > 0 and (u < n or l > 1):
x += 1
m -= u - l + 1
if l > 1:
l -= 1
if u < n:
u += 1
print(x + m // n)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def num(t):
t = t - 1
r = t * t + n
if t >= k:
r -= max(0, (t - k) * (t - k + 1) // 2)
if t >= n - k + 1:
r -= max(0, (t - (n - k + 1)) * (t - (n - k)) // 2)
return r
s = input().split()
n = int(s[0])
m = int(s[1])
k = int(s[2])
lo = 1
hi = 10**9 + 10
while lo < hi:
mid = (lo + hi + 1) // 2
if num(mid) <= m:
lo = mid
else:
hi = mid - 1
print(lo)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
n, m, k = input().split()
n = int(n)
m = int(m)
k = int(k)
m = m - n
k = k - 1
def verif(n, m, k, r):
a = r - k
b = r - (n - 1) + k
if a > 0:
u = (r - a + 1) * (a + r) // 2
else:
u = r * (r + 1) // 2
if b > 0:
v = (r - b + 1) * (b + r) // 2
else:
v = r * (r + 1) // 2
t = u + v - r
return t <= m
A = 0
B = 10**10
while B - A > 1:
r = (A + B) // 2
if verif(n, m, k, r):
A = r
else:
B = r
res = A + 1
print(res)
|
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 BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def f(n, m, k, x):
k1 = k - 1
k2 = n - k
if k1 > x - 1:
ll = (x - 1) * x // 2 + (k1 - x + 1)
else:
ll = x * k1 - k1 * (k1 + 1) // 2
if k2 > x - 1:
rr = (x - 1) * x // 2 + (k2 - x + 1)
else:
rr = x * k2 - k2 * (k2 + 1) // 2
return rr + ll + x <= m
iarr = list(map(int, input().split()))
n = iarr[0]
m = iarr[1]
k = iarr[2]
l = 1
r = m
while l <= r:
mid = (l + r) // 2
if f(n, m, k, mid):
l = mid + 1
else:
r = mid - 1
print(l - 1)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def read_input():
line = input().strip().split()
n = int(line[0])
m = int(line[1])
k = int(line[2])
p = m - n
k = max(n - k + 1, k)
y1 = k * (k - 1) // 2
y2 = (n - k) * (3 * k - 3 - n) // 2
y = y1 + y2
l = 1
if p >= y:
l += k - 1
p -= y
l += p // n
return l
else:
c = n - k
z = 0
if p != 0:
while True:
if z + 1 < c:
z0 = z**2
else:
z1 = z * (z + 1) // 2
z2 = max((n - k) * (z - 1 + z + k - n) // 2, 0)
z0 = z1 + z2
if z0 > p:
break
z += 1
return z
else:
return z + 1
print(read_input())
|
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER RETURN VAR RETURN BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def calculate_need(x, l, r):
if l > x - 1:
tl = (x - 1) * x // 2 + l - x + 1
else:
tl = (x - 1 + x - l) * l // 2
if r > x - 1:
tr = (x - 1) * x // 2 + r - x + 1
else:
tr = (x - 1 + x - r) * r // 2
t = tl + tr + x
return t
def codeforces(n, m, k):
l = k - 1
r = n - k
min_num = 1
max_num = m
result = 0
while True:
num = (min_num + max_num) // 2
need = calculate_need(num, l, r)
if need == m or num == result:
return num
elif need > m:
max_num = num - 1
elif need < m:
result = num
min_num = num + 1
n, m, k = map(int, input().split())
print(codeforces(n, m, k))
|
FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def f(tar, n, m, k):
p = 0
if k == 1 or k == n:
y = n - 1
if y > tar - 1:
a = tar * (tar - 1) // 2
b = y - (tar - 1)
p += a + b
else:
p += (tar - 1 + tar - y) * y // 2
else:
y1 = k - 1
if y1 > tar - 1:
a = tar * (tar - 1) // 2
b = y1 - (tar - 1)
p += a + b
else:
p += (tar - 1 + tar - y1) * y1 // 2
y2 = n - k
if y2 > tar - 1:
a = tar * (tar - 1) // 2
b = y2 - (tar - 1)
p += a + b
else:
p += (tar - 1 + tar - y2) * y2 // 2
p += tar
if p <= m:
return True
else:
return False
n, m, k = map(int, input().split())
low, high, ans = m // n, 10**18, m // n
while low <= high:
mid = low + (high - low) // 2
x = f(mid, n, m, k)
if x:
ans = max(ans, mid)
low = mid + 1
else:
high = mid - 1
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def check(x, n, m, k):
a = 0
if k - 1 > x - 1:
a += x * (x - 1) // 2 + k - x
else:
a += (2 * x - k) * (k - 1) // 2
b = 0
if n - k > x - 1:
b += x * (x - 1) // 2 + n - k - x + 1
else:
b += (2 * x - n + k - 1) * (n - k) // 2
if a + b + x <= m:
return True
return False
n, m, k = map(int, input().split())
l = 1
h = m
ans = 1
while l < h:
mid = (l + h + 1) // 2
if check(mid, n, m, k):
l = mid
ans = mid
else:
h = mid - 1
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
hobbit, pillow, bed = map(int, input().split())
pillow -= hobbit
start = 0
end = pillow
while start < end:
mid = round((start + end + 1) / 2)
lside = int(min(bed - 1, mid - 1))
rside = int(min(hobbit - bed, mid - 1))
needed = (
mid
+ lside * (mid - lside + (mid - 1)) / 2
+ rside * (mid - rside + (mid - 1)) / 2
)
if needed > pillow:
end = mid - 1
else:
start = mid
print(start + 1)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def pillows(n, k, h):
p = (h - 1) * h + h
left = 0
if k < h:
left = (h - k) * (h - k + 1) // 2
right = 0
if n - k + 1 < h:
right = (h - (n - k + 1)) * (h - (n - k + 1) + 1) // 2
return p - left - right
def solve(n, m, k):
p = m - n
if p == 0:
return 1
l = 0
r = 10**10
while r - l >= 2:
m = (l + r) // 2
mp = pillows(n, k, m)
if mp > p:
r = m
else:
l = m
return l + 1
if False:
assert pillows(1, 1, 10) == 10
assert solve(1, 10, 1) == 10
assert solve(5, 5, 1) == 1
assert solve(5, 5, 5) == 1
assert solve(5, 5, 3) == 1
assert solve(5, 6, 2) == 2
assert solve(5, 6, 1) == 2
assert solve(5, 6, 5) == 2
assert solve(5, 7, 5) == 2
assert solve(5, 7, 1) == 2
assert solve(5, 8, 1) == 3
assert solve(5, 8, 5) == 3
assert solve(5, 8, 4) == 2
assert solve(5, 8, 2) == 2
assert solve(5, 8, 3) == 2
assert solve(5, 9, 3) == 3
assert solve(5, 9, 2) == 3
assert solve(5, 9, 1) == 3
else:
n, m, k = list(map(int, input().split()))
print(solve(n, m, k))
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER IF NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def just_sum(n):
return n * (n + 1) // 2
def get_sum(a, b):
return just_sum(b) - just_sum(a - 1)
def check(mid, k, n, sn):
left = k - 1
right = n - k
if left < mid:
left_sum = get_sum(mid - left, mid - 1)
else:
left_sum = just_sum(mid - 1)
if right < mid:
right_sum = get_sum(mid - right, mid - 1)
else:
right_sum = just_sum(mid - 1)
return left_sum + right_sum + mid <= sn
def binary_search(n, k, sn):
low = 0
high = sn
while low < high:
mid = low + (high - low + 1) // 2
if check(mid, k, n, sn):
low = mid
else:
high = mid - 1
return low
n, m, k = map(int, input().split())
sn = m - n
print(binary_search(n, k, sn) + 1)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
from sys import stdin
__author__ = "zihaozhu"
def summation(a, b):
if a > b:
return summation(b, a)
return (b + a) * (b - a + 1) / 2
hobbits, pillow, frodo = map(int, stdin.readline().split())
lo = 1
hi = pillow
maxpossible = pillow - hobbits
while lo < hi:
mid = (lo + hi) // 2
left = max(0, mid - frodo + 1)
right = max(0, mid - (hobbits - frodo))
if summation(left, mid) + summation(right, mid) - mid > maxpossible:
hi = mid
else:
lo = mid + 1
print(lo)
|
ASSIGN VAR STRING FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
import sys
def is_able(n, m, k, mid):
res = 0
if k < mid:
res += (mid + mid - k + 1) * k // 2
else:
res += mid * (mid + 1) // 2 + k - mid
right = n - k + 1
if right < mid:
res += (mid + mid - right + 1) * right // 2
else:
res += mid * (mid + 1) // 2 + right - mid
res -= mid
return True if res <= m else False
n, m, k = map(int, input().split())
btm = 1
top = m + 1
while top - btm > 1:
mid = (top + btm) // 2
if is_able(n, m, k, mid):
btm = mid
else:
top = mid
ans = btm
print(ans)
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR RETURN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
|
def _sum_n(n):
return int(n * (n + 1) // 2)
def _sum(p, k):
return _sum_n(p) - (_sum_n(p - k) if p > k else p - k)
def _solve():
n, m, k = map(int, input().split())
low, high = 1, 2000000000.0
while low < high:
mid = int((low + high) // 2)
sum = int(_sum(mid, k) + _sum(mid - 1, n - k))
if sum < m:
low = mid + 1
elif sum > m:
high = mid - 1
else:
return mid
if _sum(low, k) + _sum(low - 1, n - k) > m:
low -= 1
return low
print(int(_solve()))
|
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.