description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
A = [input() for i in range(n)]
for i in range(n - 1, 0, -1):
if A[i] < A[i - 1]:
p = 0
while p < len(A[i]) and A[i - 1][p] <= A[i][p]:
p += 1
A[i - 1] = A[i - 1][:p]
print("\n".join(A))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
from sys import stdin, stdout
n = int(stdin.readline())
challengers = []
for i in range(n):
challengers.append(stdin.readline().strip()[1:])
for i in range(n - 2, -1, -1):
for j in range(min(len(challengers[i]), len(challengers[i + 1]))):
if challengers[i][j] < challengers[i + 1][j]:
break
elif challengers[i][j] > challengers[i + 1][j]:
challengers[i] = challengers[i][:j]
break
else:
challengers[i] = min(challengers[i], challengers[i + 1])
for i in range(n):
challengers[i] = "#" + challengers[i]
stdout.write("\n".join(challengers))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
s = input()
s = s[: len(s) - 1]
a.append(s)
for i in range(n - 2, -1, -1):
l, r = a[i], a[i + 1]
for j in range(len(l)):
if j >= len(r) or l[j] > r[j]:
a[i] = l[:j]
break
elif l[j] < r[j]:
break
for s in a:
print(s)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
a = [input() for i in range(n)]
for i in range(n - 1, 0, -1):
b = a[i]
c = a[i - 1]
l1 = len(b)
l2 = len(c)
for j in range(min(l1, l2)):
if b[j] < c[j]:
a[i - 1] = c[:j]
break
elif b[j] > c[j]:
break
else:
if l2 > l1:
a[i - 1] = a[i]
print("\n".join(a))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
def cut_to_lexicographic(word_bigger, word_smaller):
for l in range(len(word_bigger[: len(word_smaller)])):
if word_bigger[l] != word_smaller[l]:
return word_smaller[:l]
return word_bigger[: len(word_smaller)]
n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
if array[b + 1] >= array[b]:
b = b - 1
else:
array[b] = cut_to_lexicographic(array[b], array[b + 1])
print("\n".join(array))
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
inp = [0] * n
for i in range(n):
inp[i] = input()
def common_str(a, b):
l = 1
for i in range(1, len(a)):
if a[i] != b[i]:
break
l += 1
return a[:l]
for i in range(n - 1, 0, -1):
if inp[i] < inp[i - 1]:
inp[i - 1] = common_str(inp[i], inp[i - 1])
print("\n".join(inp))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return a * b / gcd(a, b)
def main():
n = int(input())
a = []
for i in range(n):
s = input()
a.append([len(s) - 2, s])
ans = 0
for i in range(n - 1, 0, -1):
if a[i][0] == 0:
ans += a[i - 1][0] + 1
a[i - 1][0] = 0
else:
k = 0
f = 0
for j in range(a[i][0] + 1):
if j > a[i - 1][0]:
f = 1
break
if a[i - 1][1][j] > a[i][1][j]:
ans += a[i - 1][0] + 1
a[i - 1][0] = j - 1
f = 1
break
if a[i - 1][1][j] < a[i][1][j]:
f = 1
break
if f == 0:
a[i - 1][0] = a[i][0]
for i in a:
print("#", end="")
for j in range(1, i[0] + 1):
print(i[1][j], end="")
print("")
return
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
ss = [input().strip() for _ in range(n)]
def compare_and_truncate(s1, s2):
if s1 > s2:
i = 0
while i < len(s2) and s1[i] == s2[i]:
i += 1
return s1[:i]
return s1
for i in range(len(ss) - 2, -1, -1):
ss[i] = compare_and_truncate(ss[i], ss[i + 1])
ans = ""
for s in ss:
ans += s + "\n"
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
from sys import stdin, stdout
def ri():
return list(map(int, input().split()))
n = int(input())
s = []
for i in range(n):
s.append(stdin.readline().strip())
for i in range(n - 1, 0, -1):
if s[i - 1] <= s[i]:
continue
else:
mind = min(len(s[i]), len(s[i - 1]))
for j in range(mind):
if s[i - 1][j] > s[i][j]:
s[i - 1] = s[i - 1][:j]
break
else:
s[i - 1] = s[i - 1][:mind]
print("\n".join(s))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
def cnt(a, b):
ln = 0
l = 0
r = len(a) - 1
if a > b:
while r > l + 1:
mid = (l + r) // 2
if a[: mid + 1] > b:
r = mid
else:
l = mid
a = a[: l + 1]
return a
n = int(input())
s = []
for i in range(n):
b = input()
s.append(b)
for i in range(n - 1, 0, -1):
s[i - 1] = cnt(s[i - 1], s[i])
for x in s:
print(x)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
def sortHashtags(htags):
def shorten(j, i):
s = 0
while s < len(htags[i]) and htags[i][s] == htags[j][s]:
s += 1
htags[j] = htags[j][:s]
n = len(htags)
for i in range(n - 1, 0, -1):
if htags[i - 1] > htags[i]:
shorten(i - 1, i)
return "\n".join(htags)
n = int(input())
tags = []
for i in range(n):
tags.append(input())
print(sortHashtags(tags))
|
FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
def g(c, d):
s = 0
while s < len(a[d]) and a[c][s] == a[d][s]:
s += 1
a[c] = a[c][:s]
def f(a):
for i in range(len(a) - 1, 0, -1):
if a[i - 1] > a[i]:
g(i - 1, i)
print("\n".join(a))
n = int(input())
a = [input() for i in range(n)]
f(a)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
tags = []
for i in range(n):
tags.append(input())
for i in range(n - 2, -1, -1):
curr = tags[i]
next = tags[i + 1]
for c in range(min(len(curr), len(next))):
if curr[c] != next[c]:
if curr[c] > next[c]:
tags[i] = curr[:c]
break
else:
if len(curr) > len(next):
tags[i] = curr[: len(next)]
print("\n".join(tags))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
def compareHesh(heshBottom, heshTop):
lenB, lenT = len(heshBottom), len(heshTop)
flag = True
for i in range(1, lenT):
if i + 1 > lenB:
return i
elif heshTop[i] > heshBottom[i]:
return i
elif heshTop[i] < heshBottom[i]:
return 0
return 0
numberHesh = int(input())
wordHesh = []
for i in range(numberHesh):
wordHesh.append(input())
for i in range(numberHesh - 1, 0, -1):
cut = compareHesh(wordHesh[i], wordHesh[i - 1])
if cut == 0:
continue
wordHesh[i - 1] = wordHesh[i - 1][:cut]
for i in range(numberHesh):
print(wordHesh[i])
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR RETURN VAR IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
from sys import stdin, stdout
n = int(stdin.readline())
A = [0] * n
for j in range(n):
A[j] = stdin.readline().strip()
answer = [0] * n
answer[-1] = A[-1]
for j in range(n - 2, -1, -1):
if A[j] <= answer[j + 1]:
answer[j] = A[j]
else:
for i in range(min(len(answer[j + 1]), len(A[j]))):
if A[j][i] > answer[j + 1][i]:
i -= 1
break
answer[j] = A[j][: i + 1]
print("\n".join(answer))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 500 000)Β β the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} β b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m β€ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
l = []
for i in range(n):
l.append(input())
def lexi(i):
j = 1
while j < len(l[i]) and l[i - 1][j] == l[i][j]:
j += 1
l[i - 1] = l[i - 1][:j]
for i in range(n - 1, 0, -1):
if l[i - 1] > l[i]:
lexi(i)
print("\n".join(l))
|
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_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for _ in range(int(input())):
p, q, r = 0, 20000, 1
n = int(input())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
l.sort()
for i in l:
if i[0] > q:
r += 1
p, q = i
else:
p = i[0]
q = min(q, i[1])
print(r)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER 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 FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def solve(intervals):
intervals.sort(key=lambda x: x[1])
cnt = 0
stack = [intervals[0]]
for i in range(1, len(intervals)):
curr = intervals[i]
if stack and curr[0] <= stack[-1][-1]:
ps, pe = stack.pop()
stack.append([max(ps, curr[0]), min(pe, curr[-1])])
else:
stack.append(curr)
return len(stack)
for _ in range(int(input())):
n = int(input())
temp = []
while n:
temp.append(list(map(lambda x: int(x), input().split())))
n -= 1
print(solve(temp))
|
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for t in range(int(input())):
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
a.sort()
m = 1
x = a[0][1]
for i in a[1:]:
s = i[0]
e = i[1]
if s > x:
m += 1
x = e
else:
x = min(x, e)
print(m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for _ in range(int(input())):
n = int(input())
vp = []
for i in range(n):
a, b = map(int, input().split())
vp.append((a, b))
ans = 1
vp.sort(key=lambda x: x[1])
mx = vp[0][1]
for it in range(1, n):
if vp[it][0] > mx:
ans += 1
mx = vp[it][1]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
T = int(input())
arr = [-1] * 2003
for i in range(T):
arr = [-1] * 2003
lst = 0
fst = 0
N = int(input())
for j in range(N):
x, y = map(int, input().split())
arr[y] = max(arr[y], x)
lst = max(lst, y)
fst = min(fst, y)
mx = -1
ans = 0
for i in range(fst, lst + 1):
if mx < arr[i]:
mx = i
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
t = int(input())
for tt in range(t):
n = int(input())
dim = []
for nn in range(n):
s, e = map(int, input().split())
dim.append((e, s))
dim.sort()
ans = 1
fi, se = dim[0]
for e, s in dim:
if s <= fi:
ans = ans
else:
fi = e
ans = ans + 1
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 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 ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for z in range(int(input())):
n = int(input())
a = []
for i in range(n):
a.append([int(x) for x in input().split()])
a.sort(key=lambda x: x[1])
x = 1
m = a[0][1]
for i in range(1, n):
if a[i][0] > m:
m = a[i][1]
x += 1
print(x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for _ in range(int(input())):
k = []
for _ in range(int(input())):
k.append([int(i) for i in input().split()])
k = sorted(k)
last_val = k[0][1]
count = 1
for i in range(1, len(k)):
if k[i][0] <= last_val:
if k[i][1] < last_val:
last_val = k[i][1]
else:
first_val = k[i][0]
last_val = k[i][1]
count += 1
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def min_bombs(interval):
interval = sorted(interval)
count = 0
last = None
for start, end in interval:
if last is None:
last = start, end
elif start > last[1]:
count += 1
last = start, end
elif end < last[1]:
last = start, end
else:
last = start, last[1]
return count + 1
TestCases = int(input())
for t in range(TestCases):
n = int(input())
interval = []
for i in range(n):
interval.append([int(x) for x in input().split()])
print(min_bombs(interval))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR VAR IF VAR NONE ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for _ in range(int(input())):
k = []
for i in range(int(input())):
k.append(list(map(int, input().split())))
k.sort(key=lambda x: x[0], reverse=True)
bomb = 1
min = k[0][0]
for j in range(1, len(k)):
if min > k[j][1]:
bomb += 1
min = k[j][0]
print(bomb)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
t = int(input())
for i in range(t):
n = int(input())
a = []
for j in range(n):
l = list(map(int, input().split()))
a.append(l)
a.sort()
b = 0
c = 0
while c < n:
b += 1
x = a[c][0]
y = a[c][1]
j = c + 1
while j < n:
if y >= a[j][0]:
x = a[j][0]
if a[j][1] < y:
y = a[j][1]
j += 1
else:
break
c = j
print(b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
m = int(input())
for t in range(m):
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
a.sort()
c = 0
temp = None
for i in a:
if temp is None:
temp = i
elif i[0] > temp[1]:
c += 1
temp = i
elif i[1] < temp[1]:
temp = i
else:
temp = [i[0], temp[1]]
print(c + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 ASSIGN VAR NONE FOR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def oneDimensionalKingdom(arr, n):
arr.sort(key=lambda x: x[1])
ans = 1
last = arr[0][1]
first = arr[0][0]
for i in range(1, n):
if arr[i][0] > last:
ans += 1
first = arr[i][0]
last = arr[i][1]
return ans
t = int(input())
for _ in range(t):
n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().split())))
print(oneDimensionalKingdom(arr, n))
|
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
t = int(input())
for f in range(t):
n = int(input())
a = []
x = 0
y = 10000000
count = 1
for i in range(n):
a.append(list(map(int, input().split())))
a.sort()
for k in a:
if k[0] > y:
count += 1
y = k[1]
else:
y = min(k[1], y)
x = k[0]
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def ss(l):
n = len(l)
l = sorted(l, key=lambda x: x[1])
ans = 0
b = -float("inf")
for i in range(n):
x, y = l[i]
if x > b:
ans += 1
b = y
return ans
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
print(ss(l))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def li():
return list(map(int, input().split()))
def si():
return input().split()
def ii():
return int(input())
def ip():
return input()
for tastcas in range(int(input())):
n = ii()
k = n
a = []
bomb = 1
for i in range(n):
a.append(tuple(li()))
a.sort(key=lambda x: x[1])
fini = a[0][1]
for i in range(1, n):
if a[i][0] > fini:
bomb += 1
fini = a[i][1]
print(bomb)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def destryKingdoms():
t = int(input())
for _ in range(t):
n = int(input())
kingdoms = []
for i in range(n):
kingdoms.append(list(map(int, input().split())))
kingdoms.sort(key=lambda x: (x[0], x[1]))
r = kingdoms[0][1]
count = 0
for i in range(1, n):
if kingdoms[i][0] > r:
count += 1
r = kingdoms[i][1]
else:
r = min(kingdoms[i][1], r)
print(count + 1)
destryKingdoms()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
t = int(input())
for _ in range(t):
n = int(input())
a = []
for _ in range(n):
a.append(list(map(int, input().split())))
a.sort()
count = 1
f1, s1 = a[0][0], a[0][1]
for i in range(len(a)):
if a[i][0] <= s1:
f1 = a[i][0]
s1 = min(s1, a[i][1])
else:
count += 1
f1 = a[i][0]
s1 = a[i][1]
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
T = int(input())
for t in range(T):
N = int(input())
kingdoms = [[int(x) for x in input().split()] for n in range(N)]
kingdoms.sort(key=lambda x: x[1])
ans = 0
newmax = -1
for i in range(len(kingdoms)):
if kingdoms[i][0] > newmax:
ans += 1
newmax = kingdoms[i][1]
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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for _ in range(int(input())):
n = int(input())
res = []
for i in range(n):
a, b = map(int, input().split())
res.append([a, b])
res = sorted(res, key=lambda x: x[1])
p, q = 0, 100000
cont = 1
for i in res:
if i[0] > q:
cont += 1
p, q = i
else:
p = i[0]
q = min(q, i[1])
print(cont)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def main():
for _ in range(int(input())):
kingdoms = sorted(
[[int(a) for a in input().split(" ")] for _ in range(int(input()))]
)
i = kingdoms[0][0]
j = kingdoms[0][-1]
bombs = 1
for a in kingdoms[1:]:
if a[0] > j:
i = a[0]
j = a[1]
bombs += 1
else:
j = a[1] if a[1] < j else j
print(bombs)
main()
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for t in range(0, int(input())):
n = int(input())
count = 0
arr = []
for i in range(0, n):
a, b = map(int, input().split())
arr.append([a, b])
arr.sort(key=lambda x: x[1])
k = -1
for i in range(0, n):
a = arr[i][0]
b = arr[i][1]
if a > k:
count += 1
k = b
print(count)
|
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
T = int(input())
for i in range(T):
N = int(input())
array = []
for j in range(N):
l = input()
array.append([int(i) for i in l.split()])
array = sorted(array)
count = 1
point = array[0][1]
for j in range(1, N):
if array[j][0] <= point:
point = min(point, array[j][1])
else:
point = array[j][1]
count += 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
t = int(input())
while t:
n = int(input())
kingdoms = []
for i in range(n):
kingdoms.append(list(map(int, input().split())))
kingdoms.sort(key=lambda x: x[1])
curr = 0
nex = 1
bombs = 0
while curr < n:
while kingdoms[nex][0] <= kingdoms[curr][1]:
nex += 1
if nex == n:
break
bombs += 1
if nex == n:
break
curr = nex
nex += 1
if nex == n:
bombs += 1
break
print(bombs)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for i in range(int(input())):
a = []
for j in range(int(input())):
a.append(input().split())
a[-1][0] = int(a[-1][0])
a[-1][1] = int(a[-1][1])
a.sort()
stack = []
numb = 1
queue = []
minv = a[0][1]
k = 0
for i in range(1, len(a)):
if a[i][0] > minv:
numb += 1
k = i
minv = a[i][1]
continue
if minv > a[i][1]:
minv = a[i][1]
print(numb)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
a, b = map(int, input().split())
l.append([a, b])
l.sort()
s = l[0][0]
e = l[0][1]
b = 0
for i in range(1, n):
if l[i][0] <= e:
s = l[i][0]
if l[i][1] <= e:
e = l[i][1]
else:
b += 1
s = l[i][0]
e = l[i][1]
print(b + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
try:
t = int(input())
for _ in range(t):
n = int(input())
dictk = [-1] * 2001
for o in range(n):
a, b = map(int, input().split())
dictk[b] = max(dictk[b], a)
maxk = -1
res = 0
for i in range(0, 2001):
if maxk < dictk[i]:
res += 1
maxk = i
print(res)
except:
pass
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def minBombs(kds):
bombs = 0
end = kds[0][1]
for kd in kds[1:]:
if kd[0] > end:
bombs += 1
end = kd[1]
else:
end = min(end, kd[1])
bombs += 1
return bombs
T = int(input())
for t in range(T):
N = int(input())
kds = []
for n in range(N):
a, b = map(int, input().split())
kds.append([a, b])
kds.sort(key=lambda kd: kd[0])
print(minBombs(kds))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin Chinese and Russian.
N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
β€ x β€ R.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.
------ Input ------
First line of the input contains T denoting number of test cases.
For each test case, first line contains N denoting the number of one dimensional kingdoms.
For each next N lines, each line contains two space separated integers a_{i} and b_{i}.
------ Output ------
For each test case , output an integer denoting the minimum number of bombs required.
------ Constraints ------
Subtask 1 (20 points) : 1 β€ T β€ 100 , 1 β€ N β€ 100 , 0 β€ a_{i} β€ b_{i} β€500
Subtask 2 (30 points) : 1 β€ T β€ 100 , 1 β€ N β€ 1000 , 0 β€ a_{i} β€ b_{i} β€ 1000
Subtask 3 (50 points) : 1 β€ T β€ 20 , 1 β€ N β€ 10^{5}, 0 β€ a_{i} β€ b_{i} β€ 2000
----- Sample Input 1 ------
1
3
1 3
2 5
6 9
----- Sample Output 1 ------
2
----- explanation 1 ------
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .
|
def printMinBombs(intervals, n):
total = n
ps, pe = -1, -1
for interval in intervals:
if pe == -1:
ps, pe = interval
elif interval[0] <= pe:
total -= 1
if interval[1] <= pe:
pe = interval[1]
else:
ps, pe = interval
return total
T = int(input())
for t in range(T):
intervals = []
n = int(input())
for i in range(n):
st, en = [int(j) for j in input().split()]
intervals.append([st, en])
intervals.sort()
print(printMinBombs(intervals, n))
|
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
l = [int(i) for i in input().split()]
l = [[l[i], i] for i in range(n)]
l.sort(reverse=1)
a = 0
b = 0
one = []
two = []
for i in range(n):
if i % 2 == 0:
a += l[i][0]
one.append(l[i][1] + 1)
else:
b += l[i][0]
two.append(l[i][1] + 1)
print(len(one))
print(*one)
print(len(two))
print(*two)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
arr = [int(x) for x in input().split()]
p = []
for i, x in enumerate(arr):
p.append([x, i + 1])
p.sort()
a = []
b = []
for i, x in enumerate(p):
if i % 2 == 0:
a.append(str(x[1]))
else:
b.append(str(x[1]))
print(len(a))
print(" ".join(a))
print(len(b))
print(" ".join(b))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
arr = list(map(int, input().split()))
idx = [i for i in range(n)]
idx.sort(key=lambda i: arr[i])
print(n // 2)
for i in range(n // 2):
print(idx[2 * i + 1] + 1, end=" ")
print()
print(n - n // 2)
for i in range(n - n // 2):
print(idx[2 * i] + 1, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
guys = list(map(int, input().split()))
guys = list(enumerate(guys))
guys.sort(key=lambda x: x[1], reverse=True)
team1 = []
skill1 = 0
team2 = []
skill2 = 0
for number, skill in guys:
if skill1 > skill2:
if len(team2) - len(team1) >= 1:
team1.append(number + 1)
skill1 += skill
continue
team2.append(number + 1)
skill2 += skill
else:
if len(team1) - len(team2) >= 1:
team2.append(number + 1)
skill2 += skill
continue
team1.append(number + 1)
skill1 += skill
print(len(team1))
for i in team1:
print(i, end=" ")
print()
print(len(team2))
for i in team2:
print(i, end=" ")
print()
|
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 EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
b = []
f = []
s = []
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
b.append((a[i], i + 1))
c = 0
for i in sorted(b):
if not c % 2:
f.append(i)
else:
s.append(i)
c += 1
print(len(f))
for i in f:
if i != f[len(f) - 1]:
print(i[1], end=" ")
else:
print(i[1])
print(len(s))
for i in s:
print(i[1], end=" ")
|
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
class Player:
def __init__(self, id, skill):
self.id = id
self.skill = skill
def __eq__(self, other):
return self.id == other.id
def __lt__(self, other):
return self.skill < other.skill
def __repr__(self):
return str(self.skill)
class Team:
def __init__(self, players, totalSkill):
self.players = players
self.totalSkill = totalSkill
n = int(input())
players = [Player(idx + 1, int(skill)) for idx, skill in enumerate(input().split())]
players = sorted(players)
teamA = Team([], 0)
teamB = Team([], 0)
for player in players:
if (
teamA.totalSkill < teamB.totalSkill
and len(teamA.players) - len(teamB.players) <= 1
):
teamA.players.append(player)
teamA.totalSkill += player.skill
else:
teamB.players.append(player)
teamB.totalSkill += player.skill
print(len(teamA.players))
print(" ".join([str(player.id) for player in teamA.players]))
print(len(teamB.players))
print(" ".join([str(player.id) for player in teamB.players]))
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
import sys
input = sys.stdin.buffer.readline
I = lambda: list(map(int, input().split()))
(n,) = I()
l = I()
ll = []
f = {}
for i in range(n):
ll.append([l[i], i])
f[i] = l[i]
ll.sort(reverse=True)
x = []
y = []
xs = 0
ys = 0
xm = max(l)
for i in range(n):
if i % 2 == 0:
x.append(ll[i][1])
xs += ll[i][0]
else:
y.append(ll[i][1])
ys += ll[i][0]
while abs(xs - ys) > xm:
temp = x.pop()
xs -= f[temp]
y.append(temp)
ys += f[temp]
print(len(x))
for i in x:
print(i + 1, end=" ")
print()
print(len(y))
for i in y:
print(i + 1, end=" ")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):
n = nmbr()
a = sorted(zip(lst(), range(1, 1 + n)), reverse=1)
team1 = []
team2 = []
for i in range(n):
if i & 1:
team1 += [a[i][1]]
else:
team2 += [a[i][1]]
print(len(team1))
print(*team1)
print(len(team2))
print(*team2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR LIST VAR VAR NUMBER VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
ar = list(map(int, input().split()))
ar1 = []
for i in range(n):
ar1.append([ar[i], i])
ar1 = sorted(ar1)
print((n + 1) // 2)
for i in range(0, n, 2):
print(ar1[i][1] + 1, end=" ")
print()
print(n // 2)
for i in range(1, n, 2):
print(ar1[i][1] + 1, end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
arr = list(map(int, input().split()))
arr = [(v, i + 1) for i, v in enumerate(arr)]
arr.sort()
left = arr[: n // 2]
right = arr[n // 2 :]
left_sum = sum([v for v, i in left])
right_sum = sum([v for v, i in right])
max_player = max([v for v, i in arr])
for i in range(n // 2):
if abs(right_sum - left_sum) <= max_player:
for j in range(i + 1, n // 2):
if abs(right_sum - left_sum) <= max_player:
break
weight = right[j][0] - left[i][0]
left[i], right[j] = right[j], left[i]
left_sum += weight
right_sum -= weight
break
weight = right[i][0] - left[i][0]
left[i], right[i] = right[i], left[i]
left_sum += weight
right_sum -= weight
print(len(left))
print(*[i for v, i in left])
print(len(right))
print(*[i for v, i in right])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
p = list(map(int, input().split()))
l = []
for i in range(n):
l.append([p[i], i + 1])
l.sort()
f = [l[0][1]]
s = [l[1][1]]
s1 = l[0][0]
s2 = l[1][0]
for i in range(2, n):
if s1 > s2:
s.append(l[i][1])
s2 = s2 + l[i][0]
elif s2 > s1:
f.append(l[i][1])
s1 = s1 + l[i][0]
elif s2 == s1:
if len(f) > len(s):
s.append(l[i][1])
s2 = s2 + l[i][0]
else:
f.append(l[i][1])
s1 = s1 + l[i][0]
print(len(f))
for i in range(len(f)):
if i != len(f) - 1:
print(f[i], end=" ")
else:
print(f[i])
print(len(s))
for i in range(len(s)):
if i != len(s) - 1:
print(s[i], end=" ")
else:
print(s[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
from sys import stdin
def arr_enu():
return sorted(
[[i + 1, int(x)] for i, x in enumerate(stdin.readline().split())],
key=lambda x: x[1],
)
n, a, team1, team2 = int(input()), arr_enu(), [], []
for i in range(n):
if i % 2:
team1.append(a[i][0])
else:
team2.append(a[i][0])
print(len(team1))
print(*team1)
print(len(team2))
print(*team2)
|
FUNC_DEF RETURN FUNC_CALL VAR LIST BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
l = [int(i) for i in input().split()]
t = sorted(l)
x = 0
y = 0
d = dict()
for i in range(len(l)):
if l[i] in d:
d[l[i]].append(i + 1)
else:
d[l[i]] = [i + 1]
a = []
b = []
for i in range(len(t)):
if x < y:
a.append(t[i])
x += t[i]
else:
b.append(t[i])
y += t[i]
print(len(a))
for i in a:
print(d[i][0], end=" ")
d[i].pop(0)
print()
print(len(b))
for i in b:
print(d[i][0], end=" ")
d[i].pop(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
lst = list(map(int, input().split()))
d = {}
for i, x in enumerate(lst):
if d.get(x) == None:
d[x] = [1]
d[x].append(i + 1)
lst.sort()
x, y, X, Y = 0, 0, [], []
for i, item in enumerate(lst):
if x <= y:
X.append(d[item][d[item][0]])
x += item
else:
Y.append(d[item][d[item][0]])
y += item
d[item][0] += 1
if n % 2 == 0:
print(n // 2)
else:
print(n // 2 + 1)
print(*X)
print(n // 2)
print(*Y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER LIST LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
arr = sorted([(int(x), i) for i, x in enumerate(input().split())])
print((len(arr) + 1) // 2)
for i in arr[::2]:
print(i[1] + 1, end=" ")
print()
print(len(arr) // 2)
for i in arr[1::2]:
print(i[1] + 1, end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
a = int(input())
z = list(map(int, input().split()))
ans = []
for i in range(len(z)):
ans.append([z[i], i])
ans.sort()
flag = 0
tan = []
i = 0
one = []
two = []
while i < len(ans):
if flag == 0:
one.append(ans[i][1] + 1)
i += 1
if i < len(ans):
two.append(ans[i][1] + 1)
flag = 1
i += 1
else:
one.append(ans[i][1] + 1)
i += 1
if i < len(ans):
two.append(ans[i][1] + 1)
flag = 1
i += 1
print(len(one))
print(*one)
print(len(two))
print(*two)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
l.append([a[i], i + 1])
l = sorted(l, key=lambda h: -1 * h[0])
a = []
b = []
for i in range(n):
if i % 2 == 0:
a.append(l[i][1])
else:
b.append(l[i][1])
print(len(a))
print(*a)
print(len(b))
print(*b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
import sys
sys.setrecursionlimit(1000000)
def solve():
(n,) = rv()
(ainput,) = rl(1)
a = [(val, i) for i, val in enumerate(ainput)]
a.sort()
a = a[::-1]
f, s = list(), list()
for i in range(len(a)):
if i % 2 == 0:
f.append(a[i][1] + 1)
else:
s.append(a[i][1] + 1)
print(len(f))
print(" ".join(map(str, f)))
print(len(s))
print(" ".join(map(str, s)))
def rv():
return map(int, input().split())
def rl(n):
return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
sys.stdin = open("test.txt")
solve()
|
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
import sys
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def input():
return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
myArr = []
for i in range(n):
myArr.append((Arr[i], i + 1))
myArr.sort()
X, Y = [], []
x_total, y_total = 0, 0
flag = 0
for i in range(n):
if flag == 0:
x_total += myArr[i][0]
X.append(myArr[i][1])
flag = 1
elif flag == 1:
y_total += myArr[i][0]
Y.append(myArr[i][1])
flag = 0
print(len(X))
print(*X)
print(len(Y))
print(*Y)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
l = [(i, num + 1) for num, i in enumerate([int(j) for j in input().split()])]
t1 = []
t2 = []
for ind, (_, num) in enumerate(sorted(l)):
if ind % 2 == 0:
t1.append(num)
else:
t2.append(num)
print(len(t1))
for i in sorted(t1):
print(i, end=" ")
print()
print(len(t2))
for i in sorted(t2):
print(i, end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n, t = int(input()), list(map(int, input().split()))
k = n // 2
a, b = t[:k], t[k:]
u, v, m = sum(a), sum(b), max(t)
a, b = list(enumerate(a, 1)), list(enumerate(b, k + 1))
i, d = 0, abs(u - v) - m
if u > v:
a, b = b, a
while d > 0:
if a[i][1] < b[i][1]:
d -= 2 * (b[i][1] - a[i][1])
a[i], b[i] = b[i], a[i]
if d < 1:
break
i += 1
print(len(a))
print(" ".join(str(i) for i, r in a))
print(len(b))
print(" ".join(str(i) for i, r in b))
|
ASSIGN VAR VAR FUNC_CALL 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 VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
import sys
input = sys.stdin.readline
for _ in range(1):
n = int(input())
arr = [int(x) for x in input().split()]
temp = [[arr[i], i] for i in range(n)]
temp.sort()
a, b = [], []
for i in range((n + 1) // 2):
if i % 2 == 0:
if i + 1 != n - i:
a.append(temp[i][1] + 1)
a.append(temp[n - i - 1][1] + 1)
else:
a.append(temp[i][1] + 1)
elif i + 1 == n - i:
b.append(temp[i][1] + 1)
else:
b.append(temp[i][1] + 1)
b.append(temp[n - i - 1][1] + 1)
if abs(len(a) - len(b)) > 1:
if len(a) > len(b):
b.append(a.pop())
else:
a.append(b.pop())
print(len(a))
print(*a)
print(len(b))
print(*b)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
def team(arr):
base = [[arr[i], i + 1] for i in range(len(arr))]
base = sorted(base, key=lambda s: s[0], reverse=True)
t1 = []
t2 = []
while base:
t1.append(base[0][1])
base.pop(0)
if base:
t2.append(base[0][1])
base.pop(0)
print(len(t1))
print(*t1)
print(len(t2))
print(*t2)
return ""
a = input()
lst = list(map(int, input().strip().split()))
print(team(lst))
|
FUNC_DEF ASSIGN VAR LIST VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = list(map(int, input().split()))
arr = []
for i in range(n):
arr.append((a[i], i + 1))
arr.sort(reverse=True)
t1 = []
t2 = []
sum1 = 0
sum2 = 0
ex = -1
if n % 2 == 1:
ex = arr[n - 1][1]
n -= 1
for i in range(0, n, 2):
if arr[i][0] >= arr[i + 1][0]:
mx = arr[i][0]
mn = arr[i + 1][0]
imx = arr[i][1]
imn = arr[i + 1][1]
else:
mn = arr[i][0]
mx = arr[i + 1][0]
imn = arr[i][1]
imx = arr[i + 1][1]
if sum1 <= sum2:
sum1 += mx
sum2 += mn
t1.append(imx)
t2.append(imn)
else:
sum1 += mn
sum2 += mx
t1.append(imn)
t2.append(imx)
if sum1 < sum2 and ex != -1:
t1.append(ex)
elif sum2 <= sum1 and ex != -1:
t2.append(ex)
print(len(t1))
for i in range(len(t1)):
print(t1[i], end=" ")
print()
print(len(t2))
for i in range(len(t2)):
print(t2[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
a = int(input())
b = input().split()
b = sorted([[int(b[i]), str(i + 1)] for i in range(0, a)], reverse=True)
c, d = [], []
sc, sd = 0, 0
while len(b) > 1:
if sc > sd:
d.append(b.pop()[1])
c.append(b.pop()[1])
else:
c.append(b.pop()[1])
d.append(b.pop()[1])
if len(b):
if sc > sd:
d.append(b.pop()[1])
else:
c.append(b.pop()[1])
print(len(c))
print(" ".join(c))
print(len(d))
print(" ".join(d))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = sorted([[int(j), i + 1] for i, j in enumerate(input().split())])
s = len(a[::2])
print(s, *[i[1] for i in a[::2]])
print(n - s, *[i[1] for i in a[1::2]])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = list(map(int, input().split()))
m = max(a)
temp = [(a[i], i + 1) for i in range(n)]
temp.sort()
teamsum = [0, 0]
cnt = [0, 0]
teams = [[], []]
minpos = 0
i = n - 1
while cnt[0] < n // 2 and cnt[1] < n // 2:
cnt[minpos] += 1
teamsum[minpos] += temp[i][0]
teams[minpos].append(temp[i][1])
i -= 1
if teamsum[0] > teamsum[1]:
minpos = 1
else:
minpos = 0
while cnt[0] < n // 2 and i >= 0:
if abs(teamsum[1] - teamsum[0]) <= m:
teamsum[0] += temp[i][0]
cnt[0] += 1
teams[0].append(temp[i][1])
else:
teamsum[1] += temp[i][0]
cnt[1] += 1
teams[1].append(temp[i][1])
i -= 1
while cnt[1] < n // 2 and i >= 0:
if abs(teamsum[1] - teamsum[0]) <= m:
teamsum[1] += temp[i][0]
cnt[1] += 1
teams[1].append(temp[i][1])
else:
teamsum[0] += temp[i][0]
cnt[0] += 1
teams[0].append(temp[i][1])
i -= 1
if n % 2 == 1:
if teamsum[0] < teamsum[1]:
teams[0].append(temp[i][1])
else:
teams[1].append(temp[i][1])
print(len(teams[0]))
print(*teams[0])
print(len(teams[1]))
print(*teams[1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST LIST LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = map(int, input().split())
a = sorted(enumerate(a, 1), key=lambda x: x[1])
a = list(a)
t1, t2 = [], []
first = True
while len(a):
if first:
t1.append(a.pop()[0])
else:
t2.append(a.pop()[0])
first = not first
print(len(t1))
print(*t1)
print(len(t2))
print(*t2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = list(map(int, input().split()))
a = [(a[i], i + 1) for i in range(n)]
a.sort()
lp = [a[x][1] for x in range(0, n, 2)]
rp = [a[x][1] for x in range(1, n, 2)]
print(len(lp))
print(*lp)
print(len(rp))
print(*rp)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = [int(i) for i in input().split()]
dic = {}
for i in range(n):
dic[a[i]] = []
for i in range(n):
dic[a[i]].append(i + 1)
a.sort()
f = []
s = []
for i in range(n):
if i & 1:
f.append(dic[a[i]][-1])
else:
s.append(dic[a[i]][-1])
dic[a[i]].pop()
print(len(f))
print(*f)
print(len(s))
print(*s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
class Player:
def __init__(self, position, skill):
self.position = position
self.skill = skill
n = int(input())
players = [Player(i + 1, x) for i, x in enumerate(map(int, input().split()))]
players.sort(key=lambda player: player.skill)
left, right = [], []
for i, player in enumerate(players):
if i % 2 == 0:
left.append(player.position)
else:
right.append(player.position)
print(len(left))
print(" ".join(map(str, left)))
print(len(right))
print(" ".join(map(str, right)))
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
i = 0
def f(a):
global i
i += 1
return a, i
a = sorted(list(map(f, map(int, input().split()))))
print(n // 2)
for i in a[1::2]:
print(i[1], end=" ")
print()
print(n - n // 2)
for i in a[0::2]:
print(i[1], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
a = list(map(int, input().split()))
di = {}
for i in range(len(a)):
di[i] = di.get(i, 0) + a[i]
d = sorted(di.items(), key=lambda kv: (kv[1], kv[0]))
dic = dict(d)
list1 = list()
list2 = list()
i = 0
for keys in dic:
if i % 2:
list2.append(keys + 1)
else:
list1.append(keys + 1)
i += 1
len1 = int((n + 1) / 2)
len2 = n - len1
print(len1)
for i in range(len1):
print(list1[i], end=" ")
print("\n{}".format(len2))
for i in range(len2):
print(list2[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
n = int(input())
arr = list(map(int, input().split()))
x = []
y = []
sx = 0
sy = 0
i = 0
ml = []
z = 0
while z < n:
ml.append([arr[z], z + 1])
z += 1
ml.sort()
for k in ml:
if sx <= sy:
sx += k[0]
x.append(k[1])
else:
sy += k[0]
y.append(k[1])
i += 1
print(len(x))
print(*x)
print(len(y))
print(*y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:
* Each boy plays for exactly one team (x + y = n).
* The sizes of teams differ in no more than one (|x - y| β€ 1).
* The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: <image>
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input
The first line contains the only integer n (2 β€ n β€ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 β€ ai β€ 104), the i-th number represents the i-th boy's playing skills.
Output
On the first line print an integer x β the number of boys playing for the first team. On the second line print x integers β the individual numbers of boys playing for the first team. On the third line print an integer y β the number of boys playing for the second team, on the fourth line print y integers β the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| β€ 1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Examples
Input
3
1 2 1
Output
2
1 2
1
3
Input
5
2 3 3 1 1
Output
3
4 1 3
2
5 2
Note
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 β€ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 β€ 2) is fulfilled.
|
import sys
def make_teams(array):
arr_2 = sorted(range(len(array)), key=lambda k: array[k])
teams = [[], []]
for i in range(len(array)):
if i % 2 == 0:
teams[0].append(arr_2[i] + 1)
else:
teams[1].append(arr_2[i] + 1)
return teams
def main():
n = sys.stdin.readline()
arr = [int(x) for x in sys.stdin.readline().split()]
teams = make_teams(arr)
for j in range(2):
sys.stdout.write(str(len(teams[j])) + "\n")
for i in range(len(teams[j])):
if i == len(teams[j]) - 1:
sys.stdout.write(str(teams[j][i]) + "\n")
else:
sys.stdout.write(str(teams[j][i]) + " ")
return
main()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING RETURN 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.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
b = b[::-1]
temp = []
for i in range(n // 2, n):
temp.append(a[i])
for i in range(0, n // 2):
temp.append(a[i])
for i in range(n):
b[i] = b[i] + temp[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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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())
for i in range(t):
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l1.sort()
l2.sort()
l11 = l2[0 : n // 2]
l2 = l2[n // 2 :]
l2.reverse()
l3 = []
l2 = l11 + l2
i = 0
while i < n:
l3.append(l1[i] + l2[i])
i += 1
l3.sort()
print(l3[n // 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 VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER 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 test in range(t):
n = int(input())
b = list(map(int, input().split()))
g = list(map(int, input().split()))
b.sort()
g.sort()
i = (n - 1) // 2
j = n - 1
mn = float("inf")
while i < n:
mn = min(mn, b[i] + g[j])
i += 1
j -= 1
print(mn)
|
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 BIN_OP VAR NUMBER 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 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())
c = n // 2
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n == 1:
print(a[0] + b[0])
continue
b = sorted(b, reverse=True)
a = sorted(a)
s = []
ans = []
for i in range(c, n, 1):
ans.append(a[i] + b[i - c])
ans.sort()
print(ans[0])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP 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.
|
for _ in range(int(input())):
numberOfBoys = int(input())
listOfBoys = list(map(int, input().split()))
listOfGirls = list(map(int, input().split()))
listOfBoys.sort()
listOfGirls.sort()
listOfHappiness = []
medianPos = int(numberOfBoys / 2)
for i in range(0, medianPos):
listOfHappiness.append(listOfGirls[i] + listOfBoys[i])
start = medianPos
end = numberOfBoys - 1
while True:
listOfHappiness.append(listOfGirls[start] + listOfBoys[end])
start += 1
end -= 1
if start >= numberOfBoys:
break
listOfHappiness.sort()
print(listOfHappiness[medianPos])
|
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 LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF 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()
k = n // 2
l = []
for i in range(k, n):
l.append(a[i] + b[n + k - i - 1])
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 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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP 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.
|
def T(A, B):
C = []
for i in range(len(A)):
C.append(A[i] + B[i])
return C
a = int(input())
for i in range(a):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if N == 1:
print(A[0] + B[0])
else:
A.sort()
B.sort()
b = int((N + 1) / 2) - 1
C = []
C += T(A[:b], B[:b])
C += T(A[b:N], B[N - 1 : b - 1 : -1])
C.sort()
c = C[int((N + 1) / 2) - 1]
print(c)
|
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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())
ali = list(map(int, input().split()))
bli = list(map(int, input().split()))
ali.sort()
bli.sort()
k = n // 2
ali = ali[k:]
bli = bli[k:]
lst = list()
ln = len(ali)
for i in range(ln):
a = ali[i] + bli[ln - i - 1]
lst.append(a)
lst.sort()
print(lst[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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER 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.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
res = float("inf")
for i in range((n - 1) // 2, n):
res = min(res, a[i] + b[n - 1])
n -= 1
print(res)
|
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 STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER 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.
|
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 = sorted(a)
b = sorted(b)
a1 = a[n // 2 :]
b1 = b[n // 2 :]
b1 = sorted(b1, reverse=True)
temp = []
for i in range(len(a1)):
x = a1[i] + b1[i]
temp.append(x)
a2 = a[: n // 2]
b2 = b[: n // 2]
b2 = sorted(b2, reverse=True)
for i in range(len(a2)):
y = a2[i] + b2[i]
temp.append(y)
temp = sorted(temp)
print(temp[n // 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL 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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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.
|
def solution():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
start = (N - 1) // 2
end = N - 1
median = 1e18
for i in range(start, N):
median = min(median, A[i] + B[end])
end -= 1
print(median)
t = int(input())
while t > 0:
t = t - 1
solution()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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())
list1 = list(map(int, input().strip().split()))
list2 = list(map(int, input().strip().split()))
list1.sort()
list2.sort()
mid = n // 2
list1 = list1[mid:]
list2 = list2[mid:]
list1.sort(reverse=True)
list3 = [(list1[i] + list2[i]) for i in range(len(list1))]
list3.sort()
print(list3[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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR 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.
|
def mxmed(n, a, b):
a.sort()
b.sort()
s = (n - 1) // 2
e = n - 1
med = 1e18
for i in range(s, n):
med = min(med, a[i] + b[e])
e = e - 1
print(med)
return
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mxmed(n, a, b)
|
FUNC_DEF 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN 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 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())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
if n == 1:
print(arr[0] + brr[0])
else:
arr.sort()
brr.sort()
arr = arr[n // 2 :]
brr = brr[n // 2 :][::-1]
ans = float("inf")
for a, b in zip(arr, brr):
ans = min(ans, a + b)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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())
while t:
n = int(input())
med = n // 2
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
new_b = b[0:med] + sorted(b[med:], reverse=True)
c = []
for i in range(n):
c.append(a[i] + new_b[i])
c = sorted(c)
print(c[med])
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER 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 VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR 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 t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
a = a[n // 2 :]
b = b[n // 2 :]
b = b[::-1]
x = 9999999999
for i in range(n - n // 2):
x = min(x, a[i] + b[i])
print(x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(sorted(map(int, input().split())))
b = list(sorted(map(int, input().split())))
c = []
s = 0
for j in range(n // 2):
c.append(a[s] + b[j])
s += 1
for k in range(n - 1, n // 2 - 1, -1):
c.append(a[s] + b[k])
s += 1
c.sort()
print(c[n // 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 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER 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 t in range(int(input())):
n = int(input())
boys = [int(s) for s in input().split()]
girls = [int(s) for s in input().split()]
boys = sorted(boys)
girls = sorted(girls)
if n == 1:
print(boys[0] + girls[0])
continue
mid = (n - 1) // 2
ans = 1e19
end = n - 1
for i in range(mid, n):
ans = min(ans, boys[i] + girls[end])
end -= 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR 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.
|
import sys
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()
e = n - 1
ans = sys.maxsize
for i in range(n // 2, n, 1):
ans = min(ans, a[i] + b[e])
e -= 1
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR 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())
l1 = sorted(map(int, input().split()))[n // 2 :]
l2 = sorted(map(int, input().split()))[n // 2 :]
r3 = min(sum(i) for i in zip(l1, l2[::-1]))
print(r3)
|
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 BIN_OP VAR NUMBER ASSIGN 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 VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.