description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) A = sorted(A)[int(N / 2) :] B = sorted(B)[int(N / 2) :] B = sorted(B, reverse=True) C = [(x + y) for x, y in zip(A, B)] sorted(C) print(min(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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
cnt = int(input()) for i in range(cnt): N = int(input()) Ais = list(map(int, input().split())) Bis = list(map(int, input().split())) Ais.sort() Bis.sort() Ais = Ais[int((N - 1) / 2) :] Bis = Bis[int((N - 1) / 2) :] Bis.sort(reverse=True) median = 2000000001 for j in range(len(Ais)): if median > Ais[j] + Bis[j]: median = Ais[j] + Bis[j] print(median)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) b = list(map(int, input().split())) g = list(map(int, input().split())) b.sort() g.sort() for i in range(n // 2): b[i] += g[i] for i in range(n // 2, n): b[i] += g[n + n // 2 - 1 - i] b.sort() print(b[n // 2])
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) brr = [] arr = [] br = [] a.sort() b.sort() for i in range(n // 2, n): arr.append(a[i]) brr.append(b[i]) for i in range(len(arr)): arr[i] += brr[len(brr) - 1 - i] print(min(arr))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for k in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ra = n // 2 a.sort() b.sort() a = a[ra:] b = b[ra:] c = [] m = len(a) for i in range(0, m): c.append(a[i] + b[m - 1 - i]) c.sort() print(c[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
import sys input = sys.stdin.readline M = int(1000000000.0) + 7 def solve(): n = int(input()) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) ans = float("inf") for i in range(n // 2, n): ans = min(ans, a[i] + b[n - i - 1 + n // 2]) return ans for _ in range(int(input())): print(solve())
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF 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 FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for T in range(int(input())): N = int(input()) A = sorted(map(int, input().split()), reverse=True)[: N // 2 + 1] B = sorted(map(int, input().split()), reverse=True)[: N // 2 + 1] print(min(A[i] + B[N // 2 - i] for i in range(N // 2 + 1)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() B.sort(reverse=1) z = [] for k in range(n // 2 + 1, n // 2 + 2): y = [] for i in range(n): y.append(A[i] + B[(i + k) % n]) y.sort() print(y[n // 2])
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for _ in range(t): n = int(input()) boys = list(map(int, input().split())) girls = list(map(int, input().split())) boys.sort() girls.sort() b = [] g = [] ans = [] for i in range(n // 2, n): b.append(boys[i]) g.append(girls[i]) g.reverse() for i in range(len(g)): ans.append(b[i] + g[i]) print(min(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input().strip())): n = int(input().strip()) arr1 = sorted(list(int(i) for i in input().strip().split())) arr2 = sorted(list(int(i) for i in input().strip().split())) temp = arr2[: n // 2] arr2 = temp + arr2[n // 2 :][::-1] new_arr = [] for i in range(n): new_arr.append(arr1[i] + arr2[i]) new_arr.sort() print(new_arr[n // 2])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) while t > 0: t -= 1 n = int(input()) a1 = [int(x) for x in input().split()] a2 = [int(x) for x in input().split()] a1.sort() a2.sort() a1 = a1[(n - 1) // 2 :] a2 = a2[(n - 1) // 2 :] a1 = a1[::-1] a = [] for i in range(len(a1)): sum = a1[i] + a2[i] a.append(sum) a.sort() print(a[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().strip().split()))[:N] B = list(map(int, input().strip().split()))[:N] A.sort() B.sort() start = (N - 1) / 2 end = N - 1 med = 1000000000000000000000000 for i in range((N - 1) // 2, N): res = A[i] + B[end] med = min(res, med) end -= 1 print(med)
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) a = sorted(list(map(int, input().split())))[n // 2 :] b = sorted(list(map(int, input().split())))[n // 2 :] b.sort(reverse=True) c = sorted([(x + y) for x, y in zip(a, b)]) print(c[0])
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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for i in range(int(input())): n = int(input()) inp1 = list(map(int, input().split())) inp1.sort() inp2 = list(map(int, input().split())) inp2.sort() if n == 1: print(inp1[0] + inp2[0]) else: r = inp1[n // 2] + inp2[n - 1] for i in range(1, n // 2 + 1): if inp1[n // 2 + i] + inp2[n - i - 1] < r: r = inp1[n // 2 + i] + inp2[n - i - 1] print(r)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): l = int(input()) lis1 = list(map(int, input().split())) lis2 = list(map(int, input().split())) lis3 = [] if len(lis1) == 1 and len(lis2) == 1: print(lis1[0] + lis2[0]) else: lis1.sort() lis2.sort() lis1 = lis1[l // 2 :] lis2 = lis2[l // 2 :] for i in range(len(lis1)): lis3.append(lis1[i] + lis2[len(lis1) - i - 1]) lis3.sort() print(lis3[0])
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort(reverse=True) half = b[n // 2 + 1 :] half1 = half[::-1] b1 = half1 + b[0 : n // 2 + 1] l = [] for i in range(0, len(a)): s = a[i] + b1[i] l.append(s) l.sort() print(l[len(l) // 2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for i in range(int(input())): n = int(input()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = [] for i in range(n // 2, n): j = n - (i - n // 2) - 1 C.append(A[i] + B[j]) C = sorted(C) print(C[0])
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 FUNC_CALL 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 VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for i in range(int(input())): n = int(input()) l1 = sorted(list(map(int, input().split()))) l2 = sorted(list(map(int, input().split()))) m = n // 2 a1 = l1[m:] a2 = l2[::-1] a = [] for i in range(len(a1)): a.append(a1[i] + a2[i]) print(min(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 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for iii in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n % 2 == 0: n2 = int(n / 2) - 1 else: n2 = int(n / 2) a.sort() b.sort() a = a[:n2] + sorted(a[n2:], reverse=True) for i in range(n): a[i] += b[i] a.sort() print(a[n2])
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() x = int(n / 2) c = [] for i in range(x): c.append(a[i] + b[i]) for i in range(x + 1): c.append(a[i + x] + b[n - i - 1]) c.sort() print(c[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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for testcase in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n == 1: print(a[0] + b[0]) continue a.sort() b.sort() arra = [] arrb = [] for i in range(n): if i < n // 2: arra.append(a[i] + b[i]) arrb.append(a[i] + b[i]) else: arra.append(a[i] + b[n - 1 - i + n // 2]) arrb.append(b[i] + a[n - 1 - i + n // 2]) arra.sort() arrb.sort() print(max(arra[n // 2], arrb[n // 2]))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a = sorted(a) b = sorted(b) start = n // 2 end = n d = 0 c = [] for i in range(start, end): d = 0 d = a[i] + b[end - 1] c.append(d) end -= 1 print(min(c))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
n = int(input()) for i in range(n): t = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() b = b[: t // 2] + sorted(b[t // 2 :], reverse=True) l = [(a[i] + b[i]) for i in range(t)] l.sort() print(l[t // 2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) l1 = list(map(int, input().split())) l2 = list(map(int, input().split())) l1.sort() l2.sort() k = n // 2 + 1 median = l1[n - 1] + l2[n - 1] for i in range(k): m = l1[k + i - 1] + l2[n - 1 - i] if m < median: median = m print(median)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for x in range(t): p = [] f = 0 N = int(input()) k = input().split() o = input().split() k = [int(y) for y in k] o = [int(y) for y in o] k.sort() o.sort() for y in range(int(N / 2), N): p.append(k[y] + o[len(k) - 1 - f]) f += 1 print(min(p))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] a.sort() b = [int(i) for i in input().split()] b.sort(reverse=True) mid = n // 2 a = a[mid:] b = b[: mid + 1] l = [] for i in range(mid + 1): l.append(a[i] + b[i]) l.sort() print(l[0])
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
def solve(N, A, B): if N == 1: return A[0] + B[0] A.sort() B.sort() start = N // 2 end = N - 1 res = float("inf") while start < N: res = min(res, A[start] + B[end]) start += 1 end -= 1 return res for i in range(int(input())): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) print(solve(N, A, B))
FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
def solve(): N = int(input()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] if N == 1: print(A[0] + B[0]) return M = (N + 1) // 2 A.sort() B.sort() ans = 10**10 i = M - 1 j = N - 1 while i < N: ans = min(ans, A[i] + B[j]) i += 1 j -= 1 print(ans) def main(): T = int(input()) while T > 0: solve() T = T - 1 main()
FUNC_DEF 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 VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] a.sort() b.sort() a = a[n // 2 :] b = b[n // 2 :] ans = 10**18 for i in range(len(a)): ans = min(ans, b[i] + a[len(a) - 1 - i]) 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) boiz = list(map(int, input().split())) grils = list(map(int, input().split())) boiz.sort() grils.sort() boiz = boiz[len(boiz) // 2 :] grils = grils[len(grils) // 2 :] ans = [] for i in range(len(boiz)): ans.append(boiz[i] + grils[len(grils) - 1 - i]) print(min(ans))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR 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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
N boys and N girls attend a dance class, where N is odd. For today's practice session, they need to form N boy-girl pairs. The i-th boy has a happiness value of A_{i} and the i-th girl has a happiness value of B_{i}. A pair consisting of the i-th boy and the j-th girl has a happiness value of A_{i} + B_{j}. Let the happiness values of the N pairs be C_{1}, C_{2}, \ldots, C_{N}. The dance instructor would like it if many of the pairs have a high happiness value, and passes the task to you β€” find the maximum possible value of the median of C, if the boy-girl pairs are chosen optimally. Note: The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of [1] is 1, the median of [1, 5, 2] is 2, and the median of [30, 5, 5, 56, 3] is 5. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} β€” the happiness values of the boys. - The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N} β€” the happiness values of the girls. ------ Output Format ------ For each test case, output on a new line the maximum possible median happiness of the N pairs. ------ Constraints ------ $1 ≀ T ≀ 3 \cdot 10^{4}$ $1 ≀ N < 3\cdot 10^{5}$ $N$ is odd $1 ≀ A_{i}, B_{i} ≀ 10^{9}$ for each valid $i$ - The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$. ------ subtasks ------ Subtask 1 (10 points): The sum of $N$ across all test cases won't exceed $10$. Subtask 2 (30 points): The sum of $N$ across all test cases won't exceed $4000$. Subtask 3 (60 points): No further constraints. ----- Sample Input 1 ------ 3 1 10 25 3 1 6 6 2 2 7 5 10 4 93 5 16 4 34 62 6 26 ----- Sample Output 1 ------ 35 8 50 ----- explanation 1 ------ Test case $1$: There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is $10 + 25 = 35$, and it is also the median. Test case $2$: Pair $A_{1}$ with $B_{3}$, $A_{2}$ with $B_{2}$, and $A_{3}$ with $B_{3}$. The happiness values are then $[1+7, 2+6, 2+6] = [8, 8, 8]$, with a median of $8$. It can be shown that this is the maximum possible median. Test case $3$: One way of achieving a median of $50$ is as follows: - Pair $A_{1}$ with $B_{3}$, for a happiness of $10 + 62 = 72$ - Pair $A_{2}$ with $B_{4}$, for a happiness of $4 + 6 = 10$ - Pair $A_{3}$ with $B_{5}$, for a happiness of $93 + 26 = 119$ - Pair $A_{4}$ with $B_{1}$, for a happiness of $5 + 4 = 9$ - Pair $A_{5}$ with $B_{2}$, for a happiness of $16 + 34 = 50$ The happiness values are $[72, 10, 119, 9, 50]$, with a median of $50$. It can be shown that no other pairing obtains a strictly larger median.
for _ in range(int(input())): n = int(input()) arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) low = 3 * pow(10, 9) mid = (n - 1) // 2 arr1.sort() arr2.sort() for i in range(mid, n): num = arr1[i] + arr2[n - (i - mid) - 1] low = min(low, num) print(low)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n, a, c = int(input()), [], 0 for i in range(n): x, y = list(map(int, input().split())) a.append([x, y]) a.sort() for i in range(n): if a[i][1] >= c: c = a[i][1] else: c = a[i][0] print(c)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) time = [] for i in range(n): tem1, tem2 = input().split() time.append([int(tem1), int(tem2)]) day = 0 remain = n time.sort() i = 0 while remain > 0: if time[i][0] > time[i][1] and day <= time[i][1]: day = time[i][1] remain -= 1 i += 1 else: day = time[i][0] remain -= 1 i += 1 print(day)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) x = [] for i in range(n): a, b = map(int, input().split()) x.append([a, b]) x = sorted(x) f = True for i in range(1, n): if x[i][1] < x[i - 1][1]: if x[i][0] >= x[i - 1][1]: x[i][1] = x[i][0] else: f = False break if f: print(x[n - 1][1]) else: print(x[n - 1][0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) dates = [] cur = 0 for i in range(n): a, b = map(int, input().split()) dates.append((b, a)) dates.sort(key=lambda x: (x[1], x[0])) for x in dates: if x[0] >= cur: cur = x[0] else: cur = x[1] print(cur)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
lst, day = sorted(list(map(int, input().split())) for _ in range(int(input()))), 0 for i, j in lst: day = [j, i][j < day] print(day)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) date = [] for _ in range(n): d = input() d = d.split() d = list(map(lambda x: int(x), d)) date.append(d) date.sort() last_date = date[-1] last_date_a = last_date[0] last_date_b = last_date[-1] date_check = 0 for d in date: if d[-1] >= date_check: date_check = d[-1] elif d[0] > date_check: date_check = d[0] print(date_check)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def build_lps_table(s): table = [0] * len(s) index = 0 for i in range(1, len(s)): if s[i] == s[index]: table[i] = index + 1 index += 1 else: index = table[i - 1] while index > 0 and s[index] != s[i]: index = table[index - 1] if s[i] == s[index]: index += 1 table[i] = index return table def main(): n = int(input()) pairs = [] for _ in range(n): a, b = [int(i) for i in input().split()] pairs.append((a, b)) pairs.sort() prev = pairs[0][1] for i in range(1, len(pairs)): if pairs[i][1] >= prev: prev = pairs[i][1] else: prev = pairs[i][0] print(prev) main()
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) arr = [] for i in range(n): tarr = list(map(int, input().split())) arr.append(tarr) arr.sort() flag = True best = 0 for i in range(n): if arr[i][0] < arr[i][0]: best = arr[i][0] elif arr[i][1] >= best: best = arr[i][1] else: best = arr[i][0] print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) dates = sorted( sorted([[int(i) for i in input().split()] for _ in range(n)], key=lambda x: x[1]), key=lambda x: x[0], ) minima = dates[0][1] for i in range(len(dates)): if dates[i][1] >= minima: minima = dates[i][1] else: minima = dates[i][0] print(minima)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
d = [0] print( ( [ (d.append(b) if b >= d[-1] else d.append(a)) for a, b in sorted( [list(map(int, input().split())) for i in range(int(input()))] ) ] + d )[-1] )
ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
cycle = int(input()) l0 = [] for n in range(cycle): l0.append(tuple(map(int, input().split()))) l0.sort() l1 = [l0[0][1]] for n in range(cycle - 1): if l0[n + 1][1] >= l1[n]: l1.append(l0[n + 1][1]) elif l0[n + 1][0] >= l1[n]: l1.append(l0[n + 1][0]) else: l1.append(l1[n]) print(l1[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) def line(): return list(map(int, input().split())) d = [] for _ in range(n): d.append(line()) d.sort() flag = True day = 0 for i in range(n): if d[i][1] >= day: day = d[i][1] else: day = d[i][0] print(day)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) a = sorted([tuple(map(int, input().split())) for _ in range(n)]) prev = 0 for big, small in a: prev = small if prev <= small else big print(prev)
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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) dates = [] for i in range(n): line = input().split() dates.append([int(line[0]), int(line[1])]) dates.sort() curr_date = 0 for date in dates: if curr_date <= date[1]: curr_date = date[1] else: curr_date = date[0] print(curr_date)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
q = int(input()) inputlist = [] for j in range(q): inputlist.append(list(map(int, input().split()))) def Sorter(sub_li): auxilliary = sorted(sub_li, key=lambda x: x[0]) leftend = 0 rightend = 0 j = 0 while j < len(auxilliary) - 1: key = auxilliary[j][0] if auxilliary[j + 1][0] == key: leftend = j rightend = j + 1 while auxilliary[j][0] == key: rightend = j j += 1 if j == len(auxilliary): break auxilliary[leftend : rightend + 1] = sorted( auxilliary[leftend : rightend + 1], key=lambda x: x[1] ) else: j += 1 continue return auxilliary daylist = Sorter(inputlist) dayorder = [daylist[0][1]] for j in range(1, len(daylist)): if daylist[j][1] < dayorder[j - 1]: dayorder.append(daylist[j][0]) else: dayorder.append(daylist[j][1]) print(dayorder[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
class Exam: def __init__(self, actual, early): self.actual = actual self.early = early exams = [] n = int(input()) for i in range(n): a, e = map(int, input().split()) exams.append(Exam(a, e)) exams.sort(key=lambda x: (x.actual, x.early)) minimum = -1 for i in range(n): if minimum <= exams[i].early: minimum = exams[i].early else: minimum = exams[i].actual print(minimum)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) x = [] y = [] for i in range(n): ai, bi = map(int, input().split()) x.append(ai) y.append(bi) zipped_pairs = zip(x, y) data = [i for _, i in sorted(zipped_pairs)] record = 0 x.sort() for i in range(n): if data[i] >= record: record = data[i] else: record = x[i] print(record)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) a = [] for i in range(n): a.append([int(i) for i in input().split()]) a.sort() mn = min(a[0]) for i in range(len(a)): if a[i][1] >= mn: mn = a[i][1] else: mn = a[i][0] print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
m = [] a = [] for _ in range(int(input())): l, r = [int(x) for x in input().split()] m.append(l) a.append(r) d = sorted(zip(m, a)) mina = -1 for l, r in d: if r >= mina: mina = r else: mina = l print(mina)
ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) l = [] for i in range(n): l.append([int(x) for x in input().split()]) l.sort() curDay = 0 for a, b in l: if b >= curDay: curDay = b else: curDay = a print(curDay)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) exams = [] max_date = 0 for i in range(n): a, b = map(int, input().split()) if a > max_date: max_date = a exams.append([a, b]) exams.sort() i = 0 last_day = 0 now = exams[i][1] while i < n - 1: if now > exams[i + 1][1]: now = exams[i + 1][0] else: now = exams[i + 1][1] i += 1 print(now)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) l = [] for i in range(n): ch = input() l1 = ch.split() l.append((int(l1[0]), int(l1[1]))) l.sort() m = l[0][1] i = 1 while i < len(l): if l[i][1] >= m: m = l[i][1] else: m = l[i][0] i = i + 1 print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) dic = {} for i in range(n): a, b = map(int, input().split()) if a in dic: dic[a].append(b) else: dic[a] = [b] ans = [] f = 0 for key in sorted(dic.keys()): for i in sorted(dic[key]): if len(ans) == 0: ans.append(min(dic[key])) f = min(dic[key]) elif i >= f: ans.append(i) f = i else: ans.append(key) f = key print(ans[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) l = [] s = [] for i in range(n): a, b = input().split() l.append([int(a), int(b)]) l.sort() v = l[0][1] for i in range(1, n): if l[i][1] < v: v = l[i][0] else: v = l[i][1] print(v)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def input_data(): n = int(input()) return [tuple(map(int, input().split())) for line in range(n)] data = sorted(input_data()) last_day = data[0][1] for day in data: last_day = day[1] if day[1] >= last_day else day[0] print(last_day)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) x, p = n * [0], n * [0] for i in range(0, n): x[i], p[i] = map(int, input().split()) x, p = (list(t) for t in zip(*sorted(zip(x, p)))) list1 = [x[0], p[0]] c = min(list1) for i in range(1, n): list1 = [x[i], p[i]] j = min(list1) if j >= c: c = j else: c = max(list1) print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR LIST NUMBER BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
every = [] for i in range(int(input())): line = list(map(int, input().split())) every.append(line) every.sort(key=lambda x: x[1]) every.sort(key=lambda x: x[0]) day = every[0][1] for i in every: if i[1] >= day: day = i[1] else: day = i[0] print(day)
ASSIGN VAR LIST FOR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
I = lambda: list(map(int, input().split(" "))) n = int(input()) lst = [] for _ in range(n): lst.append(I()) lst = sorted(lst) c = min(lst[0]) for i in range(1, len(lst)): cur = lst[i] c = cur[1] if cur[1] >= c else cur[0] print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def find_last_date(exams): dates = [] sorted_exams = sorted(exams, key=lambda ex: (ex[0], ex[1])) prev = 0 for act_date, poss_date in sorted_exams: if poss_date >= prev: dates.append(poss_date) prev = poss_date else: dates.append(act_date) prev = act_date return dates[-1] exams = [[int(e) for e in input().split()] for _ in range(int(input()))] print(find_last_date(exams))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def main(): day = [] for _ in range(int(input())): day.append(tuple(map(int, input().split()))) day = sorted(day) last = 0 for x in day: if last <= x[1]: last = x[1] else: last = x[0] print(last) main()
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) arr = [] for _ in range(n): a, b = map(int, input().split()) arr.append((a, b)) arr.sort() cnt = 0 if n == 1: print(min(arr[0])) else: prev = arr[0][1] for i in range(1, n): if arr[i][1] >= prev: prev = arr[i][1] cnt = arr[i][1] elif arr[i][0] >= prev: prev = arr[i][0] cnt = arr[i][0] print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
t = [] x = int(input()) for k in range(x): t.append(list(map(int, input().split()))) t.sort() u = t[0][0] y = min(t[0]) if x > 1: for j in range(1, x): if t[j][0] > y and t[j][1] < y: u = t[j][0] y = t[j][0] elif t[j][1] > y and t[j][0] < y: u = t[j][0] y = t[j][1] elif t[j][1] >= y and t[j][0] >= y: a = t[j][1] - y b = t[j][0] - y if a <= b: u = t[j][0] y = t[j][1] elif b <= a: u = t[j][0] y = t[j][0] print(y)
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) input_list = [] for _ in range(n): input_list.append([int(x) for x in input().split()]) def my_fun(the_list, num): the_list.sort() min_date = 0 for i in range(n): if min_date <= input_list[i][1]: min_date = input_list[i][1] else: min_date = input_list[i][0] print(min_date) my_fun(input_list, n)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) M = [list(map(int, input().split())) for i in range(n)] M.sort() g = 0 for i in range(n): if min(M[i][0], M[i][1]) < g: g = max(M[i][0], M[i][1]) else: g = min(M[i][0], M[i][1]) print(g)
ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) a, b = [], [] for i in range(n): i, j = map(int, input().split()) a.append(i) b.append(j) z = sorted(zip(a, b)) l = [z[0][1]] for i in range(1, len(z)): if z[i][1] >= l[i - 1]: l.append(z[i][1]) else: l.append(z[i][0]) print(l[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
y = sorted( [list(map(int, input().split())) for _ in range(int(input()))], key=lambda k: [k[0], k[1]], ) ans = -1 for i in y: ans = i[1] if ans <= i[1] else i[0] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
days = [] for i in range(int(input())): days.append(list(map(int, input().split()))) days.sort(key=lambda x: (x[0], x[1])) lastDay = 0 for el in days: if el[1] >= lastDay: lastDay = el[1] else: lastDay = el[0] print(lastDay)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
nrofexams = int(input("")) exams = [] for i in range(nrofexams): line = input("").split() tup = int(line[0]), int(line[1]) exams.append(tup) exams = sorted(exams) date = 0 for i in range(len(exams)): if date <= exams[0][1]: date = exams[0][1] else: date = exams[0][0] exams.pop(0) print(date)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def exams(nums): nums.sort() ans = nums[0][1] for i in range(len(nums)): if ans <= nums[i][1]: ans = nums[i][1] else: ans = nums[i][0] return ans n = int(input().strip()) nums = [] for i in range(n): a, b = map(int, input().strip().split()) nums.append((a, b)) print(exams(nums))
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) l = sorted([[*map(int, input().split())] for _ in " " * n]) a = 0 for i in l: if i[1] < a: a = i[0] else: a = max(a, i[1]) print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) m = [tuple(map(int, input().split())) for _ in range(n)] m = sorted(m) minn = m[0][1] for i in range(1, n): if minn <= m[i][1]: minn = m[i][1] else: minn = m[i][0] print(minn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) days = [list(map(int, input().split())) for i in range(n)] days.sort() L = [0] for i in range(n): if days[i][1] >= L[i]: L.append(days[i][1]) else: L.append(days[i][0]) print(L[-1])
ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) q = [] for i in range(n): s = input().split() a = int(s[0]) b = int(s[1]) q.append([a, b]) q.sort() cur = q[0][1] for i in range(1, n): if cur > q[i][1]: cur = q[i][0] else: cur = q[i][1] print(cur)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
li = [] for i in range(int(input())): a, b = map(int, input().split()) li.append([a, b]) li = sorted(li) day_final = li[0][1] for j in li: if j[1] > day_final: day_final = j[1] if j[1] < day_final: day_final = j[0] else: continue print(day_final)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) ls = [list(map(int, input().split())) for _ in range(n)] ls.sort() m = 0 ck = False for l in ls: if m <= l[1]: m = l[1] else: m = l[0] print(m)
ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) l = [] for x in range(n): l.append([int(y) for y in input().split()]) def f(x): return x[0], x[1] l.sort(key=f) date = [l[0][1]] for z in range(1, n): if l[z][1] >= max(date): date.append(l[z][1]) else: date.append(l[z][0]) print(max(date))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) lst = [] lst1 = [] for i in range(n): lst.append([int(i) for i in input().split()]) if n == 1: ans = lst[0][1] else: m = sorted(lst, key=lambda x: (x[0], x[1])) day = m[0][1] for i in range(n - 1): if m[i + 1][1] >= day: day = m[i + 1][1] else: day = m[i + 1][0] ans = day print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
nofsubjects = int(input()) subject_list = [] for i in range(nofsubjects): subject = input() subject = subject.split(" ") subject[0] = int(subject[0]) subject[1] = int(subject[1]) subject_list.append(subject) subject_list.sort() nofdays = subject_list[0][1] subject_list.pop(0) while subject_list != []: if nofdays <= subject_list[0][1]: nofdays = subject_list[0][1] else: nofdays = subject_list[0][0] subject_list.pop(0) print(nofdays)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR LIST IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
class Exam: def __init__(self, a, b): self.a = a self.b = b def __lt__(self, other): if self.a == other.a: return self.b < other.b return self.a < other.a n = int(input()) exams = [] for i in range(n): a, b = [int(x) for x in input().split()] exams.append(Exam(a, b)) last = 0 for exam in sorted(exams): if exam.b >= last: last = exam.b else: last = exam.a print(last)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) A, B = list(), list() check = set() for i in range(n): a, b = map(int, input().split()) A.append(a) B.append(b) check.add(a) check = sorted(check) val = dict() for x in check: val[x] = list() for i in range(n): val[A[i]].append(B[i]) main_lst = list() for x in check: val[x].sort() itr, ans = 0, 0 for x in check: if itr == 0: prev = max(val[x]) itr += 1 elif prev > min(val[x]): prev = x else: prev = max(val[x]) print(prev)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def main(): (n,) = read() a = [] for i in range(n): a.append(tuple(read())) a.sort() day = 0 for i in range(n): if day <= a[i][1]: day = a[i][1] else: day = a[i][0] print(day) def read(mode=2): inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return list(map(int, inputs.split())) def write(s="\n"): if s is None: s = "" if isinstance(s, list): s = " ".join(map(str, s)) s = str(s) print(s, end="") write(main())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF STRING IF VAR NONE ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) li = [] for i in range(n): li += [list(map(int, input().rstrip().split()))] li.sort(key=lambda x: x[0]) t = min(li[0]) day = li[0][0] for i in range(1, n): if min(li[i]) >= t: t = min(li[i]) elif day == li[i][0] and min(li[i]) <= t: continue else: t = max(li[i]) day = li[i][0] print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) arr = [] for i in range(n): a, b = list(map(int, input().split())) arr.append([a, b]) arr.sort(key=lambda x: x[0] + float(x[1]) / 20000000) end = -1 for i in range(len(arr)): if arr[i][1] >= end: end = arr[i][1] else: end = arr[i][0] print(end)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) a = [([0] * 2) for x in range(n)] for x in range(n): a[x] = list(map(int, input().split())) a = sorted(a, key=lambda x: x[1]) a = sorted(a, key=lambda x: x[0]) l = min(a[0]) for x in range(1, n): if min(a[x]) >= l: l = min(a[x]) else: l = max(a[x]) print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
t = int(input()) dates = [] for i in range(t): a1, b1 = map(int, input().split()) a = [a1, b1] dates.append(a) dates.sort() if t == 1: print(dates[0][1]) else: if dates[1][1] >= dates[0][1]: l = dates[0][1] else: l = dates[0][0] for i in range(1, t): if dates[i][1] < l: l = dates[i][0] else: l = dates[i][1] print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) li = [] for i in range(n): li.append([int(i) for i in input().split()]) li.sort(reverse=True) last = li.pop()[-1] while li: if li[-1][-1] >= last: last = li.pop()[-1] else: last = li.pop()[0] print(last)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR IF VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) p = [] for i in range(n): a, b = map(int, input().split()) p.append([a, b]) p.sort(key=lambda x: (x[0], x[1])) d = {} for pair in p: if not pair[0] in d: d[pair[0]] = [] d[pair[0]].append(pair[1]) ks = list(d.keys()) cur = max(d[ks[0]]) for i in range(1, len(ks)): mi = min(d[ks[i]]) if cur <= mi: cur = max(d[ks[i]]) else: cur = ks[i] print(cur)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) a = list() b = list() for i in range(n): x, y = input().split() a.append([int(x), i]) b.append(int(y)) a.sort() day = b[a[0][1]] for i in range(1, n): if b[a[i][1]] >= day: day = b[a[i][1]] elif a[i][0] == a[i - 1][0]: day = max(day, b[a[i][1]]) else: day = a[i][0] print(day)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
import sys n = int(input()) abn = [] for i in range(n): a, b = map(int, sys.stdin.readline().split()) abn.append((a, b)) abn.sort(key=lambda x: (x[0], x[1])) ans = -1 for i in range(n): if ans <= abn[i][1]: ans = abn[i][1] else: ans = abn[i][0] print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) L = [] for k in range(n): a, b = map(int, input().split()) L.append((a, b)) L = sorted(L) aux = 0 for k in range(n): if min(L[k]) < aux: aux = max(L[k]) else: aux = min(L[k]) print(aux)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
import sys data = sys.stdin.read().strip() data = data.split("\n") exams = int(data[0]) for i in range(1, len(data)): data[i] = data[i].split(" ") data[i][0] = int(data[i][0]) data[i][1] = int(data[i][1]) days = data[1:] data = None days.sort() ordered = True first = days[0][1] for i in range(1, len(days)): if days[i][1] < first: first = days[i][0] else: first = days[i][1] print(first)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NONE EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input().strip()) l = [] for _ in range(n): a, b = input().strip().split() l.append((int(a), int(b))) l.sort() date = 0 for a, b in l: if b > date: date = b if b < date: date = a print(date)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) lst = [[0, 0]] * n for i in range(n): lst[i] = list(map(int, input().split())) lst.sort() day = lst[0][1] for i in range(1, len(lst)): if day <= lst[i][1] and day: day = lst[i][1] elif day <= lst[i][0]: day = lst[i][0] else: break print(day)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) cur_day = 0 y = [tuple(map(int, input().split())) for _ in range(n)] y.sort() for a, b in y: if b >= cur_day: cur_day = b else: cur_day = a print(cur_day)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) D = [] for _ in range(n): D.append(tuple(map(int, input().split()))) D.sort() date = 0 for d in D: if date <= min(d[0], d[1]): date = min(d[0], d[1]) else: date = d[0] print(date)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input()) p = [] for i in range(n): a, b = map(int, input().split()) p.append((a, b)) p.sort(key=lambda x: (x[0], x[1])) prev = p[n - 1][1] possible = True for i in reversed(range(n - 1)): if prev >= p[i][0]: prev = p[i][0] elif prev >= p[i][1]: prev = p[i][1] else: possible = False break if possible: print(p[n - 1][1]) else: print(p[n - 1][0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
n = int(input("")) ab = [] total = 0 for i in range(n): ab.append(tuple(int(x) for x in input("").split(" "))) ab.sort() for i in range(n): total = ab[i][0] if ab[i][1] < total else ab[i][1] print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
def main(): n = int(input()) days = [] for i in range(n): a, b = map(int, input().split()) days.append((a, b)) days.sort() first = [] second = [] first.append(days[0][0]) second.append(days[0][1]) for i in range(1, n): day = days[i] if day[1] >= first[-1]: first.append(day[1]) elif day[0] >= first[-1]: first.append(day[0]) if day[1] >= second[-1]: second.append(day[1]) elif day[0] >= second[-1]: second.append(day[0]) print(min(first[-1], second[-1])) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order. According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai. Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. Input The first line contains a single positive integer n (1 ≀ n ≀ 5000) β€” the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≀ bi < ai ≀ 109) β€” the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. Output Print a single integer β€” the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. Examples Input 3 5 2 3 1 4 2 Output 2 Input 3 6 1 5 2 4 3 Output 6 Note In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5. In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.
N = int(input()) dates = [] for i in range(N): pair = tuple(map(int, input().split())) dates.append(pair) dates.sort() MinDay = min(dates[0]) for i in dates[1:]: if i[0] >= MinDay and i[1] >= MinDay: MinDay = min(i) elif MinDay >= min(i): MinDay = max(i) print(MinDay) dates.clear()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR