description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
s = input()
t = input()
indl = [(-1) for i in range(len(t))]
j = 0
for i in range(len(s)):
if s[i] == t[j]:
indl[j] = i
j += 1
if j == len(t):
break
indr = [(-1) for i in range(len(t))]
j = len(t) - 1
for i1 in range(len(s)):
i = len(s) - 1 - i1
if s[i] == t[j]:
indr[j] = i
j -= 1
if j == -1:
break
l = indr[0]
for i in range(len(t) - 1):
l = max(l, indr[i + 1] - indl[i] - 1)
l = max(l, len(s) - 1 - indl[len(t) - 1])
print(l)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
string = str(input())
substring = str(input())
len_string = len(string)
len_substring = len(substring)
minimal_string_pos = []
max_string_pos = []
sub_flag = 0
for i in range(len_string):
if string[i] == substring[sub_flag]:
minimal_string_pos.append(i)
sub_flag += 1
if sub_flag > len_substring - 1:
break
sub_flag = len(substring) - 1
for i in range(len_string - 1, -1, -1):
if string[i] == substring[sub_flag]:
max_string_pos.append(i)
sub_flag -= 1
if sub_flag < 0:
break
max_string_pos = max_string_pos[::-1]
digit_max_1 = max(
max_string_pos[0], len_string - minimal_string_pos[len(minimal_string_pos) - 1] - 1
)
digit_max_2 = 0
for i in range(len(substring) - 1):
digit_max_2 = (
max_string_pos[i + 1] - minimal_string_pos[i] - 1
if max_string_pos[i + 1] - minimal_string_pos[i] - 1 > digit_max_2
else digit_max_2
)
print(max(digit_max_1, digit_max_2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
R = lambda: map(int, input().split())
s = input()
t = input()
ls, lt = len(s), len(t)
a = [0] * lt
j = ls - 1
for i in reversed(range(lt)):
while s[j] != t[i]:
j -= 1
a[i] = j
j -= 1
res, l = 0, 0
for i in range(ls):
rp = ls - 1
if l < lt:
rp = a[l] - 1
res = max(res, rp - i + 1)
if l < lt and s[i] == t[l]:
l += 1
print(res)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
word = input()
sub = input()
n = len(word)
m = len(sub)
LR = []
RL = []
ind = 0
for i in range(n):
if sub[ind] == word[i]:
LR.append(i)
ind += 1
if ind == m:
break
ind = m - 1
for i in range(n - 1, -1, -1):
if sub[ind] == word[i]:
RL.append(i)
ind -= 1
if ind == -1:
break
RL.reverse()
mn = max(n - LR[-1] - 1, RL[0])
for i in range(m - 1):
d = RL[i + 1] - LR[i] - 1
if d > mn:
mn = d
print(mn)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
s = input()
t = input()
lefts = [(0) for i in range(len(t))]
rights = [(0) for i in range(len(t))]
i = 0
j = 0
while i < len(s) and j < len(t):
if s[i] == t[j]:
lefts[j] = i
j += 1
i += 1
i = len(s) - 1
j = len(t) - 1
while i >= 0 and j >= 0:
if s[i] == t[j]:
rights[j] = i
j -= 1
i -= 1
ans = max(len(s) - lefts[-1] - 1, rights[0])
for i in range(len(t) - 1):
ans = max(ans, rights[i + 1] - lefts[i] - 1)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
def int_multiple():
return [int(c) for c in input().split()]
def int_single():
return int(input())
def str_multiple():
return [c for c in input().split()]
def str_single():
return input()
s = str_single()
t = str_single()
ti = 0
start = []
for si in range(len(s)):
if s[si] == t[ti]:
start.append(si)
ti += 1
if ti == len(t):
break
end = []
ti = len(t) - 1
for si in reversed(list(range(len(s)))):
if s[si] == t[ti]:
end.append(si)
ti -= 1
if ti < 0:
break
end = list(reversed(end))
start_mx = len(s) - start[-1] - 1
end_mx = end[0]
mx_between = 0
for i in range(len(t) - 1):
diff = end[i + 1] - start[i] - 1
mx_between = max(mx_between, diff)
print(max(start_mx, end_mx, mx_between))
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
s = input().rstrip()
t = input().rstrip()
left = []
idx = 0
for i, item in enumerate(s):
if item == t[idx]:
left.append(i)
idx += 1
if idx == len(t):
break
right = []
idx = len(t) - 1
for i, item in enumerate(s[::-1]):
if item == t[idx]:
right.append(len(s) - i - 1)
idx -= 1
if idx == -1:
break
right.reverse()
ans = max(right[0], len(s) - right[-1] - 1)
ans = max(ans, left[0], len(s) - left[-1] - 1)
for l, r in zip(left, right[1:]):
ans = max(ans, r - l - 1)
print(ans)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
s = input()
t = input()
L1 = []
L2 = []
ptr = 0
for i in range(0, len(s)):
if s[i] == t[ptr]:
L1.append(i)
ptr += 1
if ptr >= len(t):
break
ptr = len(t) - 1
for i in range(len(s) - 1, -1, -1):
if s[i] == t[ptr]:
L2.append(i)
ptr -= 1
if ptr < 0:
break
L2 = L2[::-1]
mx = -1
for i in range(0, len(L1) - 1):
mx = max(mx, L2[i + 1] - L1[i] - 1)
mx = max(mx, L2[0])
mx = max(mx, len(s) - L1[-1] - 1)
print(mx)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
s = input()
t = input()
def search(s, t):
indext = 0
pos = [-1]
for i in range(len(s)):
if indext < len(t) and s[i] == t[indext]:
pos += [i]
indext += 1
if indext == len(t):
return pos
pos = search(s, t)
right = len(s) - 1
ans = right - pos[-1]
for i in range(len(t))[::-1]:
while s[right] != t[i]:
right -= 1
right -= 1
ans = max(ans, right - pos[i])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
a = list(input())
b = list(input())
l = [(0) for i in range(len(a))]
r = [(0) for i in range(len(a))]
itr = 0
m = len(b)
n = len(a)
for i in range(len(a)):
if itr < m and b[itr] == a[i]:
itr += 1
l[i] = itr
itr = 0
for i in range(len(a)):
if itr < m and b[m - 1 - itr] == a[n - 1 - i]:
itr += 1
r[n - 1 - i] = itr
ans = 0
for i in range(n):
left = 1
right = n - i
mid = 0
while left <= right:
mid = (left + right) // 2
if l[i] + r[i + mid - 1] >= m:
ans = max(ans, mid - 2)
left = mid + 1
else:
right = mid - 1
for i in range(n):
if l[i] == 1:
ans = max(ans, i)
break
for i in range(n):
if l[n - 1 - i] == m:
ans = max(ans, i)
for i in range(n):
if r[i] == m:
ans = max(ans, i)
for i in range(n):
if r[n - 1 - i] == 1:
ans = max(ans, i)
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
def f(s, t):
right = [0] * len(t)
for i in reversed(range(len(t))):
pos = len(s) - 1
if i + 1 < len(t):
pos = right[i + 1] - 1
while s[pos] != t[i]:
pos -= 1
right[i] = pos
ans = 0
pos = 0
for i in range(len(s)):
rpos = len(s) - 1
if pos < len(t):
rpos = right[pos] - 1
ans = max(ans, rpos - i + 1)
if pos < len(t) and t[pos] == s[i]:
pos += 1
return ans
s = input()
t = input()
print(f(s, t))
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
The only difference between easy and hard versions is the length of the string.
You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$.
If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$).
Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Input-----
The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters.
It is guaranteed that $t$ is a subsequence of $s$.
-----Output-----
Print one integer β the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$.
-----Examples-----
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
S = input()
T = input()
N, M = len(S), len(T)
def calc(s, t):
X = [0] * len(s)
j = 0
for i in range(len(s)):
if j >= len(t):
X[i] = j
elif s[i] == t[j]:
X[i] = j + 1
j += 1
else:
X[i] = X[i - 1]
return [0] + X
A, B = calc(S, T), calc(S[::-1], T[::-1])[::-1]
l, r = 0, N
while r - l > 1:
m = (l + r) // 2
C = [(A[i] + B[i + m]) for i in range(N - m + 1)]
if max(C) >= M:
l = m
else:
r = m
print(l)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
(*data,) = sys.stdin.read().split("\n")[::-1]
def input():
return data.pop()
for _ in range(int(input())):
n, l, r = map(int, input().split())
(*socks,) = map(int, input().split())
left_colors = [0] * n
right_colors = [0] * n
for v in socks[:l]:
left_colors[v - 1] += 1
for v in socks[l:]:
if left_colors[v - 1]:
left_colors[v - 1] -= 1
l -= 1
r -= 1
else:
right_colors[v - 1] += 1
n = l + r
cost = 0
if l < r:
l, r = r, l
left_colors, right_colors = right_colors, left_colors
disb = n // 2 - r
for i, v in enumerate(left_colors):
diff = min(disb, v // 2)
cost += diff
disb -= diff
left_colors[i] -= diff * 2
l -= diff * 2
n = l + r
print(cost + n // 2 - min(l, r) + n // 2)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
cl = [(0) for _ in range(n)]
cr = [(0) for _ in range(n)]
socks = list(map(int, input().split()))
for x in socks[:l]:
cl[x - 1] += 1
if r > 0:
for x in socks[l:]:
cr[x - 1] += 1
if l > r:
cl, cr = cr, cl
for i in range(n):
g = min(cl[i], cr[i])
cl[i] -= g
cr[i] -= g
diff = abs(r - l) // 2
cost = 0
i = 0
while diff > 0 and i < n:
if cr[i] > 1:
cr[i] -= 2
diff -= 1
cost += 1
else:
i += 1
print(sum(cr) + cost)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
from sys import stdin, stdout
def INI():
return int(stdin.readline())
def INL():
return [int(_) for _ in stdin.readline().split()]
def INS():
return stdin.readline()
def MOD():
return pow(10, 9) + 7
def OPS(ans):
stdout.write(str(ans) + "\n")
def OPL(ans):
[stdout.write(str(_) + " ") for _ in ans]
stdout.write("\n")
for _ in range(INI()):
n, l, r = INL()
X = INL()
D1 = dict()
for _ in range(l):
if X[_] in D1:
D1[X[_]] += 1
else:
D1[X[_]] = 1
D2 = dict()
for _ in range(l, n):
if X[_] in D2:
D2[X[_]] += 1
else:
D2[X[_]] = 1
D1.get(X[_], 0) + 1
for _ in D1:
if _ in D2:
if D1[_] < D2[_]:
D2[_] -= D1[_]
D1[_] = 0
else:
D1[_] -= D2[_]
D2[_] = 0
ans = 0
x, y = 0, 0
for _ in D1:
x += D1[_]
for _ in D2:
y += D2[_]
if x < y:
ans = x
for _ in D2:
if x:
if D2[_] % 2 == 1:
D2[_] -= 1
x -= 1
for _ in D2:
if x < D2[_]:
D2[_] -= x
x = 0
break
else:
x -= D2[_]
D2[_] = 0
for _ in D2:
ans += (D2[_] + 1) // 2
OPS(ans)
else:
ans = y
for _ in D1:
if y:
if D1[_] % 2 == 1:
D1[_] -= 1
y -= 1
for _ in D1:
if y < D1[_]:
D1[_] -= y
y = 0
break
else:
y -= D1[_]
D1[_] = 0
for _ in D1:
ans += (D1[_] + 1) // 2
OPS(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR FOR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for tc in range(int(input())):
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
if l == r:
dic = {}
for i in range(l):
if c[i] not in dic:
dic[c[i]] = 0
dic[c[i]] += 1
left = r
for i in range(l, n):
if c[i] in dic and dic[c[i]] > 0:
dic[c[i]] -= 1
left -= 1
print(left)
elif l > r:
dic = {}
for i in range(l):
if c[i] not in dic:
dic[c[i]] = 0
dic[c[i]] += 1
left = r
for i in range(l, n):
if c[i] in dic and dic[c[i]] > 0:
dic[c[i]] -= 1
left -= 1
rem = (l - r) // 2
ans = 0
for i in dic:
if rem == 0:
break
if dic[i] >= 2:
s = dic[i] // 2 if dic[i] // 2 <= rem else rem
rem -= s
dic[i] -= s * 2
ans += s
print(ans + left + 2 * rem)
elif r > l:
dic = {}
for i in range(l, n):
if c[i] not in dic:
dic[c[i]] = 0
dic[c[i]] += 1
left = l
for i in range(l):
if c[i] in dic and dic[c[i]] > 0:
dic[c[i]] -= 1
left -= 1
rem = (r - l) // 2
ans = 0
for i in dic:
if rem == 0:
break
if dic[i] >= 2:
s = dic[i] // 2 if dic[i] // 2 <= rem else rem
rem -= s
dic[i] -= s * 2
ans += s
print(ans + left + 2 * rem)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for i in range(t):
n, l, r = [int(x) for x in input().split()]
lis = [int(x) for x in input().split()]
dict1 = dict()
dict2 = dict()
for i in range(l):
dict1[lis[i]] = dict1.get(lis[i], 0) + 1
for i in range(l, r + l):
if lis[i] in dict1 and dict1[lis[i]] > 0:
dict1[lis[i]] -= 1
else:
dict2[lis[i]] = dict2.get(lis[i], 0) + 1
cost = 0
sum_left = sum([x for x in dict1.values()])
sum_right = sum([x for x in dict2.values()])
if sum_left == sum_right:
print(sum_left)
elif sum_left > sum_right:
max_2 = sum([(x // 2) for x in dict1.values()])
if max_2 * 2 >= sum_left - sum_right:
print(sum_right + (sum_left - sum_right) // 2)
else:
print(max_2 + sum_right + (sum_left - sum_right - max_2 * 2))
else:
max_2 = sum([(x // 2) for x in dict2.values()])
if max_2 * 2 >= sum_right - sum_left:
print(sum_left + (sum_right - sum_left) // 2)
else:
print(max_2 + sum_left + (sum_right - sum_left - max_2 * 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
T = int(input())
for _ in range(T):
N, L, R = map(int, input().split())
C = list(map(int, input().split()))
MAX_C = max(C)
LC = [(0) for i in range(MAX_C + 1)]
RC = [(0) for i in range(MAX_C + 1)]
for i in range(L):
LC[C[i]] += 1
for i in range(L, N):
RC[C[i]] += 1
for i in range(MAX_C + 1):
common = min(LC[i], RC[i])
LC[i] -= common
RC[i] -= common
L -= common
R -= common
ans = 0
for i in range(MAX_C + 1):
if LC[i] > 1 and L > R:
diff = min((L - R) // 2, LC[i] // 2)
LC[i] -= diff * 2
ans += diff
L -= diff * 2
elif RC[i] > 1 and R > L:
diff = min((R - L) // 2, RC[i] // 2)
RC[i] -= diff * 2
ans += diff
R -= diff * 2
mn = min(L, R)
ans += mn
delta = max(L, R) - mn
ans += delta
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
def solve(N, L, R, A):
my_dict = {}
for a in A:
my_dict[a] = [0, 0]
for i in range(L):
my_dict[A[i]][0] += 1
for i in range(L, N):
my_dict[A[i]][1] += 1
mks = list(my_dict.keys())
recolor = 0
for mk in mks:
recolor += abs(my_dict[mk][0] - my_dict[mk][1])
recolor /= 2
if L < R:
imbalance = (R - L) / 2
fixable = 0
for mk in mks:
if my_dict[mk][1] - my_dict[mk][0] > 0:
fixable += (my_dict[mk][1] - my_dict[mk][0]) // 2
else:
imbalance = (L - R) / 2
fixable = 0
for mk in mks:
if my_dict[mk][0] - my_dict[mk][1] > 0:
fixable += (my_dict[mk][0] - my_dict[mk][1]) // 2
plus = imbalance - fixable
if plus > 0:
recolor += plus
print(int(recolor))
def run():
out = ""
T = int(input())
for i in range(T):
N, L, R = [int(x) for x in sys.stdin.readline().split()]
A = [int(x) for x in sys.stdin.readline().split()]
solve(N, L, R, A)
run()
|
IMPORT FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
def main():
t = int(input())
for i in range(t):
solve()
def solve():
n, l, r = map(int, input().split())
a = list(map(int, input().split()))
r = a[l:]
l = a[:l]
r.sort()
l.sort()
matched = 0
pass
pl = len(l) - 1
pr = len(r) - 1
while pr != -1 and pl != -1:
if r[pr] == l[pl]:
matched += 1
r.pop(pr)
l.pop(pl)
pl -= 1
pr -= 1
elif r[pr] > l[pl]:
pr -= 1
else:
pl -= 1
half = 0
if len(r) - len(l) >= 2:
for i in range(len(r) - 2, -1, -1):
if i < len(r) - 1 and r[i] == r[i + 1]:
r.pop(i + 1)
r.pop(i)
half += 1
if len(r) == len(l):
break
if len(l) - len(r) >= 2:
for i in range(len(l) - 2, -1, -1):
if i < len(l) - 1 and l[i] == l[i + 1]:
l.pop(i + 1)
l.pop(i)
half += 1
if len(l) == len(r):
break
print(n - matched * 2 - half - min(len(r), len(l)))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
def main():
n, l, r = map(int, input().split())
k = n // 2
c = list(map(int, input().split()))
c1, c2 = c[:l], c[l:]
delta = abs(r - l) // 2
p1, p2 = [0] * n, [0] * n
for i in range(l):
p1[c1[i] - 1] += 1
for i in range(r):
p2[c2[i] - 1] += 1
ans = 0
for i in range(n):
while p1[i] > 0 and p2[i] > 0:
p1[i] -= 1
p2[i] -= 1
k -= 1
if l > r:
for i in range(n):
while p1[i] >= 2 and delta > 0:
delta -= 1
p1[i] -= 2
k -= 1
ans += 1
elif l < r:
for i in range(n):
while p2[i] >= 2 and delta > 0:
delta -= 1
p2[i] -= 2
k -= 1
ans += 1
if delta != 0:
ans += delta * 2
k -= delta
ans += k
print(ans)
for _ in range(int(input())):
main()
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
a = [*map(int, input().split())]
b = {}
c = {}
p, q = l, r
for i in range(n):
if i < l:
b[a[i]] = b.get(a[i], 0) + 1
else:
x = b.get(a[i], 0)
if x == 1:
p -= 1
q -= 1
del b[a[i]]
elif x > 1:
p -= 1
q -= 1
b[a[i]] -= 1
else:
c[a[i]] = c.get(a[i], 0) + 1
if q > p:
p, q = q, p
b, c = c, b
ans = q
p -= q
for i in b.values():
pr = i // 2
if p - 2 * pr < 0:
pr = p // 2
p -= 2 * pr
ans += pr
break
else:
p -= 2 * pr
ans += pr
ans += p
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, l, r = map(int, input().split())
left = [(0) for __ in range(n)]
right = [(0) for __ in range(n)]
a = list(map(int, input().split()))
for i in range(l):
left[a[i] - 1] += 1
for i in range(l, n):
right[a[i] - 1] += 1
for i in range(n):
min_cnt = min(left[i], right[i])
left[i] -= min_cnt
right[i] -= min_cnt
l -= min_cnt
r -= min_cnt
ans = 0
if l < r:
l, r = r, l
left, right = right, left
for i in range(n):
extra = l - r
can_do = left[i] // 2
do = min(can_do * 2, extra)
ans += do // 2
l -= do
ans += (l - r) // 2 + (l + r) // 2
print(ans)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for i in range(int(input())):
n, l, r = map(int, input().split())
C = [int(i) for i in input().split()]
cost, cost1, cost2 = 0, 0, 0
C1 = C[:l]
C2 = C[l:]
d1, d2 = dict(), dict()
for i in C1:
if i in d1:
d1[i] += 1
else:
d1[i] = 1
for j in C2:
if j in d2:
d2[j] += 1
else:
d2[j] = 1
for i in d1:
if i in d2:
x1 = d1[i]
x2 = d2[i]
sub = min(x1, x2)
d1[i] = x1 - sub
d2[i] = x2 - sub
sum1, sum2 = 0, 0
d1_1, d1_pair = 0, 0
for i in d1:
sum1 += d1[i]
if d1[i] == 1:
d1_1 += 1
else:
d1_pair += d1[i] - d1[i] % 2
d1_1 += d1[i] % 2
d2_1, d2_pair = 0, 0
for i in d2:
sum2 += d2[i]
if d2[i] == 1:
d2_1 += 1
else:
d2_pair += d2[i] - d2[i] % 2
d2_1 += d2[i] % 2
rem = abs(sum1 - sum2)
costa = min(sum1, sum2)
if sum1 > sum2:
if d1_pair >= rem:
costa += rem / 2
else:
ref = rem - d1_pair
costa += d1_pair / 2
costa += ref
elif sum1 < sum2:
if d2_pair >= rem:
costa += rem / 2
else:
ref = rem - d2_pair
costa += d2_pair / 2
costa += ref
print(int(costa))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.buffer.readline
def map_int():
return map(int, input().split())
def solve():
n, l, r = map_int()
c = list(map_int())
if r > l:
c = c[l:n] + c[:l]
l, r = r, l
color = [0] * (n + 1)
for i in range(n):
color[c[i]] += 1 if i < l else -1
ans = rem = n // 2 - r
bad = 0
for cnt in color:
if cnt > 1:
used = min(cnt // 2, rem)
cnt -= 2 * used
rem -= used
if cnt > 0:
bad += cnt
print(ans + bad - rem)
for _ in range(int(input())):
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for i in range(int(input())):
n, l, r = map(int, input().split())
allsocks = list(map(int, input().split()))
leftsocks = sorted(allsocks[:l])
rightsocks = sorted(allsocks[l:])
a = b = 0
while a < l and b < r:
if leftsocks[a] < rightsocks[b]:
a += 1
elif leftsocks[a] > rightsocks[b]:
b += 1
else:
leftsocks[a] = rightsocks[b] = 0
a += 1
b += 1
ll = l - leftsocks.count(0)
lr = r - rightsocks.count(0)
same = 0
p = 0
if l > r and ll > 1:
while p < l - 1:
if leftsocks[p] == leftsocks[p + 1] and leftsocks[p] != 0:
same += 1
p += 2
else:
p += 1
if r > l and lr > 1:
while p < r - 1:
if rightsocks[p] == rightsocks[p + 1] and rightsocks[p] != 0:
same += 1
p += 2
else:
p += 1
print(abs(l - r) // 2 + (ll + lr) // 2 - min(abs(l - r) // 2, same))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
arr = list(map(int, input().split()))
dictl = {}
for i in range(l):
if dictl.get(arr[i]) is None:
dictl[arr[i]] = 0
dictl[arr[i]] = dictl[arr[i]] + 1
dictr = {}
for i in range(l, n):
if dictr.get(arr[i]) is None:
dictr[arr[i]] = 0
dictr[arr[i]] = dictr[arr[i]] + 1
for k in dictl.keys():
if dictr.get(k) is None:
continue
mini = min(dictl[k], dictr[k])
dictl[k] -= mini
dictr[k] -= mini
r -= mini
l -= mini
res = min(l, r)
if l < r:
diff = (r - l) // 2
for k in dictr.keys():
if diff == 0:
break
m = min(diff, dictr[k] // 2)
res += m
diff -= m
res += diff * 2
else:
diff = (l - r) // 2
for k in dictl.keys():
if diff == 0:
break
m = min(diff, dictl[k] // 2)
res += m
diff -= m
res += diff * 2
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
colors = [([0] * 2) for _ in range(n)]
cost = 0
L = c[:l]
R = c[l:]
for i in L:
if colors[i - 1][1] > 0:
colors[i - 1][1] -= 1
else:
colors[i - 1][0] += 1
for i in R:
if colors[i - 1][0] > 0:
colors[i - 1][0] -= 1
else:
colors[i - 1][1] += 1
lpair = 0
rpair = 0
for i in range(n):
lpair += colors[i][0] // 2
rpair += colors[i][1] // 2
lcnt = 0
rcnt = 0
for i in range(n):
if colors[i][0]:
lcnt += colors[i][0]
if colors[i][1]:
rcnt += colors[i][1]
cost += min(rcnt, lcnt)
if rcnt == lcnt:
print(cost)
continue
v = max(rcnt, lcnt)
diff = abs(rcnt - lcnt)
if v == lcnt:
if lpair * 2 >= diff:
cost += diff // 2
else:
cost += diff - lpair
elif rpair * 2 >= diff:
cost += diff // 2
else:
cost += diff - rpair
print(cost)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
def makeDict(left):
leftMap = {}
for item in left:
if item not in leftMap:
leftMap[item] = 0
leftMap[item] += 1
return leftMap
for _ in range(t):
n, l, r = map(int, input().split())
left = list(map(int, input().split()))
right = []
while len(left) > l:
right.append(left.pop())
leftMap = makeDict(left)
rightMap = makeDict(right)
lkeys = set(leftMap.keys())
rkeys = set(rightMap.keys())
for k in lkeys:
if k in rkeys:
mn = min(leftMap[k], rightMap[k])
leftMap[k] -= mn
if not leftMap[k]:
leftMap.pop(k)
rightMap[k] -= mn
if not rightMap[k]:
rightMap.pop(k)
left = []
right = []
a, b = sum(leftMap.values()), sum(rightMap.values())
if a < b:
leftMap, rightMap = rightMap, leftMap
a, b = b, a
elif a == b:
pass
lkeys = leftMap.keys()
gap = abs(a - b)
cost = 0
vals = sorted(leftMap.values(), reverse=True)
for i in range(len(vals)):
val = vals[i]
while gap and val >= 2:
gap -= 2
vals[i] -= 2
val -= 2
cost += 1
X = sum(vals)
while gap:
cost += 2
X -= 2
gap -= 2
cost += X
print(cost)
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, left, right = map(int, input().split())
arr1 = [0] * n
arr2 = [0] * n
for i, x in enumerate(map(int, input().split())):
if i < left:
arr1[x - 1] += 1
else:
arr2[x - 1] += 1
result = abs(left - right) // 2
diff_pairs = result
sum_pos = sum_neg = 0
for i in range(n):
diff = arr2[i] - arr1[i]
if diff:
diff_pairs_local = 0
if diff_pairs:
diff_pairs_local = min(abs(diff) // 2, diff_pairs)
if diff > 0:
sum_pos += diff
else:
sum_neg += -diff
if (right - left) * diff > 0:
diff_pairs -= diff_pairs_local
if diff > 0:
sum_pos -= diff_pairs_local * 2
else:
sum_neg -= diff_pairs_local * 2
result += max(sum_pos, sum_neg) - diff_pairs
print(result)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n, l, r = map(int, input().split())
C = list(map(int, input().split()))
L = [0] * n
R = [0] * n
for i in range(n):
if i < l:
L[C[i] - 1] += 1
else:
R[C[i] - 1] += 1
for i in range(n):
MIN = min(L[i], R[i])
L[i] -= MIN
R[i] -= MIN
PL = 0
PR = 0
SUML = 0
SUMR = 0
for i in range(n):
SUML += L[i]
SUMR += R[i]
PL += L[i] // 2
PR += R[i] // 2
if SUML == SUMR:
print(SUML)
continue
elif SUMR > SUML:
change = (SUMR - SUML) // 2
ANS = SUML + change * 2 - min(change, PR)
print(ANS)
else:
change = (SUML - SUMR) // 2
ANS = SUMR + change * 2 - min(change, PL)
print(ANS)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for u in range(int(input())):
n, l, r = map(int, input().split())
x = []
x.append([(0) for i in range(n)])
x.append([(0) for i in range(n)])
y = [int(w) for w in input().split()]
for i in range(n):
t = y[i]
if i < l:
x[0][t - 1] += 1
else:
x[1][t - 1] += 1
for i in range(n):
t = min(x[0][i], x[1][i])
x[0][i] -= t
x[1][i] -= t
a1 = 0
a2 = 0
for i in range(n):
a1 += x[0][i]
a2 += x[1][i]
ans = 0
if a1 < a2:
i = 0
while i < n and a1 != a2:
if x[1][i] > 1:
a2 -= 2
x[1][i] -= 2
ans += 1
i -= 1
i += 1
else:
i = 0
while i < n and a1 != a2:
if x[0][i] > 1:
a1 -= 2
x[0][i] -= 2
ans += 1
i -= 1
i += 1
ans = ans + max(a1, a2)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
tests = inp()
for _ in range(tests):
n, l, r = invr()
c = inlt()
colourCount = [[0, 0] for _ in range(n)]
for ii in range(l):
colourCount[c[ii] - 1][0] += 1
for ii in range(l, n):
colourCount[c[ii] - 1][1] += 1
totalCost = 0
spareLeft = 0
spareRight = 0
for col in colourCount:
matches = min(col)
col[0] -= matches
col[1] -= matches
if l > r:
matches = min(col[0] // 2, (l - r) // 2)
l -= matches
r += matches
col[0] -= matches * 2
totalCost += matches
elif r > l:
matches = min(col[1] // 2, (r - l) // 2)
l += matches
r -= matches
col[1] -= matches * 2
totalCost += matches
matches = min(col[0], spareRight)
spareRight -= matches
col[0] -= matches
spareLeft += col[0]
totalCost += matches
matches = min(col[1], spareLeft)
spareLeft -= matches
col[1] -= matches
spareRight += col[1]
totalCost += matches
totalCost += spareLeft + spareRight
print(totalCost)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
C = list(map(int, input().split()))
d = {}
for i in range(1, n + 1):
d.update({i: [0, 0]})
for i in range(l):
d[C[i]][0] += 1
for i in range(l, n):
d[C[i]][1] += 1
c = n // 2 - min(l, r)
s = 0
for i in d:
x = (d[i][1] + d[i][0]) // 2 - min(d[i])
if s + x <= c:
if d[i][0] <= d[i][1] and l <= r:
d[i][0] += x
d[i][1] -= x
s += x
elif d[i][0] > d[i][1] and l > r:
d[i][0] -= x
d[i][1] += x
s += x
elif d[i][0] <= d[i][1] and l <= r:
d[i][0] += c - s
d[i][1] -= c - s
s = c
elif d[i][0] > d[i][1] and l > r:
d[i][0] -= c - s
d[i][1] += c - s
s = c
if s < c:
for i in d:
if s == c:
break
if l < r and d[i][0] < d[i][1]:
d[i][0], d[i][1] = d[i][1], d[i][0]
s += 1
elif l > r and d[i][0] > d[i][1]:
d[i][0], d[i][1] = d[i][1], d[i][0]
s += 1
for i in d:
if d[i][0] > d[i][1]:
c += d[i][0] - d[i][1]
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR DICT VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for tk in range(t):
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
d1 = {}
d2 = {}
for i in range(l):
d1[c[i]] = d1.get(c[i], 0) + 1
for i in range(l, n):
d2[c[i]] = d2.get(c[i], 0) + 1
for i in d1.keys():
x = min(d1[i], d2.get(i, 0))
d1[i] = d1[i] - x
d2[i] = d2.get(i, 0) - x
v1 = d1.values()
v2 = d2.values()
s1 = sum(v1)
s2 = sum(v2)
s = abs(s1 - s2)
s = s // 2
if s == 0:
print(s1)
else:
ans = max(s1, s2)
if s1 > s2:
for i in d1:
a = d1[i] // 2
if s - a >= 0:
ans -= a
s -= a
else:
ans -= s
break
if s == 0:
break
print(ans)
else:
for i in d2:
a = d2[i] // 2
if s - a >= 0:
ans -= d2[i] // 2
s -= d2[i] // 2
else:
ans -= s
break
if s == 0:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
In = sys.stdin.readline
T = int(In())
for tc in range(1, T + 1):
n, l, r = map(int, In().split())
color = [(0) for _ in range(n + 1)]
socks = list(map(int, In().split()))
visited = {}
left, right = {"total": 0, "odd": 0}, {"total": 0, "odd": 0}
answer = 0
for i in range(l):
color[socks[i]] += 1
visited[socks[i]] = True
for i in range(l, n):
color[socks[i]] -= 1
visited[socks[i]] = True
for key in visited.keys():
temp = color[key]
if temp == 0:
continue
if temp > 0:
left["total"] += temp
if temp % 2 != 0:
left["odd"] += 1
else:
temp = -temp
right["total"] += temp
if temp % 2 != 0:
right["odd"] += 1
if left["total"] >= right["total"]:
answer += right["total"]
left["odd"] -= right["total"]
if left["odd"] > 0:
answer += left["odd"]
answer += (left["total"] - right["total"] - left["odd"]) // 2
else:
answer += (left["total"] - right["total"]) // 2
else:
answer += left["total"]
right["odd"] -= left["total"]
if right["odd"] > 0:
answer += right["odd"]
answer += (right["total"] - left["total"] - right["odd"]) // 2
else:
answer += (right["total"] - left["total"]) // 2
print(answer)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR DICT STRING STRING NUMBER NUMBER DICT STRING STRING NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR STRING VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING NUMBER ASSIGN VAR VAR VAR STRING VAR IF BIN_OP VAR NUMBER NUMBER VAR STRING NUMBER IF VAR STRING VAR STRING VAR VAR STRING VAR STRING VAR STRING IF VAR STRING NUMBER VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR STRING VAR STRING VAR STRING NUMBER VAR BIN_OP BIN_OP VAR STRING VAR STRING NUMBER VAR VAR STRING VAR STRING VAR STRING IF VAR STRING NUMBER VAR VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR STRING VAR STRING VAR STRING NUMBER VAR BIN_OP BIN_OP VAR STRING VAR STRING NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
cs = set(c)
lc = []
rc = []
for i in range(n):
if i < l:
lc.append(c[i])
else:
rc.append(c[i])
ll = [0] * (n + 1)
rr = [0] * (n + 1)
for i in range(len(lc)):
ll[lc[i]] += 1
for i in range(len(rc)):
rr[rc[i]] += 1
cost = 0
sl = 0
sr = 0
for i in cs:
t = min(ll[i], rr[i])
ll[i] -= t
sl += ll[i]
rr[i] -= t
sr += rr[i]
if sl < sr:
for i in cs:
if sl and rr[i] and rr[i] % 2 != 0:
rr[i] -= 1
cost += 1
sl -= 1
if sl == 0:
break
if sl != 0:
while sl:
for i in cs:
if rr[i] and sl > 1:
rr[i] -= 2
sl -= 2
cost += 2
elif sl == 1:
if rr[i]:
rr[i] -= 1
sl -= 1
cost += 1
if sl == 0:
break
srr = 0
for i in cs:
if rr[i]:
cost += rr[i] // 2
if rr[i] % 2 != 0:
rr[i] = 1
srr += 1
cost += srr
else:
for i in cs:
if sr and ll[i] and ll[i] % 2 != 0:
ll[i] -= 1
sr -= 1
cost += 1
if sr == 0:
break
if sr != 0:
while sr:
for i in cs:
if ll[i] and sr > 1:
ll[i] -= 2
sr -= 2
cost += 2
elif sr == 1:
if ll[i]:
ll[i] -= 1
sr -= 1
cost += 1
if sr == 0:
break
srr = 0
for i in cs:
if ll[i]:
cost += ll[i] // 2
if ll[i] % 2 != 0:
ll[i] = 1
srr += 1
cost += srr
print(cost)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER WHILE VAR FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER WHILE VAR FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for case in range(1, t + 1):
n, le, ri = [int(x) for x in input().split(" ")]
socks = [int(x) for x in input().split(" ")]
ans = 0
left = {}
for sock in socks[:le]:
if sock in left:
left[sock] += 1
else:
left[sock] = 1
right = {}
for sock in socks[le:]:
if sock in left and left[sock] != 0:
left[sock] -= 1
le -= 1
ri -= 1
elif sock in right:
right[sock] += 1
else:
right[sock] = 1
if ri > le:
le, ri = ri, le
left, right = right, left
ans += ri
le -= ri
for num in left.values():
pairs = num // 2
if le - 2 * pairs < 0:
pairs = le // 2
le -= 2 * pairs
ans += pairs
break
else:
le -= 2 * pairs
ans += pairs
ans += le
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
def sign(x):
return 1 if x > 0 else -1
def main():
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
d = {}
for i in range(n):
if c[i] not in d:
if i < l:
d[c[i]] = 1
else:
d[c[i]] = -1
elif i < l:
d[c[i]] += 1
else:
d[c[i]] -= 1
total = 0
cnt = ab_cnt = 0
for k in d:
cnt += d[k]
ab_cnt += abs(d[k])
sc = sign(cnt)
ab = abs(cnt)
for k in d:
if d[k] == 0:
continue
if sc == sign(d[k]):
goods = abs(d[k]) // 2 * 2
if goods >= ab:
d[k] -= ab * sign(d[k])
total += ab // 2
ab_cnt -= ab
ab = 0
break
else:
d[k] -= goods * sign(d[k])
ab -= goods
total += goods // 2
ab_cnt -= goods
total += ab
ab_cnt -= ab
total += ab_cnt // 2
print(total)
main()
|
FUNC_DEF RETURN VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
N, L, R = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
A[i] -= 1
if L > R:
A = A[L:] + A[:L]
L, R = R, L
C = [0] * N
for i in range(L):
C[A[i]] += 1
for i in range(L, N):
C[A[i]] -= 1
X = R - L >> 1
Y = X
F = [0] * N
for i in range(L):
F[i] = 1
for i in range(L, N):
if C[A[i]] <= -2 and X > 0:
C[A[i]] += 2
X -= 1
F[i] = 1
print(Y + (sum([abs(C[i]) for i in range(N)]) >> 1))
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.readline
def inI():
inputLine = input().split()
return int(inputLine[0]) if len(inputLine) == 1 else map(int, inputLine)
def inIL():
return list(map(int, input().split()))
def inCL():
return list(input())[:-1]
def out(*liste):
if isinstance(liste[0], list):
liste = liste[0]
for element in liste:
print(element, end=" ")
print()
t = inI()
for it in range(t):
n, l, r = inI()
socks = inIL()
left, right = socks[:l], socks[l:]
if l < r:
left, right = right, left
r, l = l, r
nbleft = [0] * (n + 1)
sumleft = l
nbright = [0] * (n + 1)
sumright = r
for color in left:
nbleft[color] += 1
for color in right:
nbright[color] += 1
for color in range(1, n + 1):
paired = min(nbleft[color], nbright[color])
nbleft[color] -= paired
sumleft -= paired
nbright[color] -= paired
sumright -= paired
nbop = 0
for color in range(1, n + 1):
if sumleft <= sumright:
break
switch = min(nbleft[color] // 2, (sumleft - sumright) // 2)
nbop += switch
nbleft[color] -= 2 * switch
sumleft -= 2 * switch
nbop += sumleft
print(nbop)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
g = int(input())
while g > 0:
g -= 1
n, L, R = map(int, input().split())
a = list(map(int, input().split()))
l = {}
r = {}
for i in range(n):
if i < L:
if a[i] not in l:
l[a[i]] = 0
l[a[i]] += 1
else:
if a[i] not in r:
r[a[i]] = 0
r[a[i]] += 1
if R > L:
l, r = r, l
L, R = R, L
ans = 0
for i in l:
if i in r:
t = min(l[i], r[i])
l[i] -= t
r[i] -= t
L -= t
R -= t
diff = L - R
for i in l:
if diff > 0:
t = min(diff, l[i]) // 2
diff -= t * 2
L -= t * 2
l[i] -= t * 2
ans += t
print(ans + L)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
n, l, r = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
color = {}
for a in range(l, n):
if color.get(arr[a]) != None:
color[arr[a]] += 1
else:
color[arr[a]] = 1
left = {}
for a in range(l):
if left.get(arr[a]) != None:
left[arr[a]] += 1
else:
left[arr[a]] = 1
right = color.keys()
l = 0
ans = 0
rr = 0
for r in right:
if left.get(r) != None:
if left[r] < color[r]:
color[r] = color[r] - left[r]
left[r] = 0
else:
left[r] = left[r] - color[r]
color[r] = 0
l = sum(left.values())
rr = sum(color.values())
lkeys = left.keys()
if l == rr:
ans = l
else:
if l > rr:
for i in lkeys:
if left[i] > 1:
while rr != l and left[i] > 1:
left[i] = left[i] - 2
l -= 2
ans += 1
if l == rr:
break
else:
for i in right:
if color[i] > 1:
while rr != l and color[i] > 1:
color[i] -= 2
rr -= 2
ans += 1
if l == rr:
break
ans += abs(l - rr) // 2 + (l + rr) // 2
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR FOR VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for f in range(t):
n, l, r = map(int, input().split())
p = [int(x) for x in input().split()]
le = p[0:l]
ri = p[l:]
le.sort()
ri.sort()
i = 0
j = 0
le1 = []
ri1 = []
while i < l and j < r:
if le[i] == ri[j]:
i += 1
j += 1
elif le[i] > ri[j]:
ri1.append(ri[j])
j += 1
else:
le1.append(le[i])
i += 1
while i < l:
le1.append(le[i])
i += 1
while j < r:
ri1.append(ri[j])
j += 1
cost = 0
if l > r:
i = 1
while i < len(le1) and cost != (l - r) / 2:
if le1[i] == le1[i - 1]:
cost += 1
i += 2
else:
i += 1
print(len(le1) - cost)
else:
j = 1
while j < len(ri1) and cost != (r - l) / 2:
if ri1[j] == ri1[j - 1]:
cost += 1
j += 2
else:
j += 1
print(len(ri1) - cost)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
from sys import *
ws = lambda: map(int, stdin.readline().strip().split())
li = lambda: list(map(int, stdin.readline().strip().split()))
mod = 1000000007
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = num * (n - i) % p
den = den * (i + 1) % p
return num * pow(den, p - 2, p) % p
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def prod(l):
ans = 1
for i in range(len(l)):
ans = ans * l[i]
return ans
def sortindex(l, a):
c = []
if a == -1:
rev = True
else:
rev = False
for i in range(len(l)):
c.append([l[i], i])
x = sorted(c, reverse=rev)
return x
for _ in range(int(input())):
n, le, rr = ws()
lis = li()
l = [0] * (n + 1)
r = [0] * (n + 1)
for i in range(n):
if i < le:
l[lis[i]] += 1
else:
r[lis[i]] += 1
temp = n // 2 - min(le, rr)
ans = temp
matches = 0
if le > rr:
for i in range(n + 1):
if temp == 0:
break
if l[i] > r[i]:
c = (l[i] + r[i]) // 2 - r[i]
if c == 0:
continue
if c <= temp:
temp -= c
l[i] -= c
r[i] += c
else:
l[i] -= temp
r[i] += temp
temp = 0
elif rr > le:
for i in range(n + 1):
if temp == 0:
break
if r[i] > l[i]:
c = (l[i] + r[i]) // 2 - l[i]
if c == 0:
continue
if c <= temp:
temp -= c
l[i] += c
r[i] -= c
else:
l[i] += temp
r[i] -= temp
temp = 0
for i in range(n + 1):
if l[i] != 0 and r[i] != 0:
matches += min(l[i], r[i])
ans += n // 2 - matches
print(ans)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
N, L, R = map(int, input().split())
X = list(map(int, input().split()))
C1 = [0] * N
C2 = [0] * N
for i in range(N):
if i < L:
C1[X[i] - 1] += 1
else:
C2[X[i] - 1] += 1
if L > R:
C2, C1 = C1, C2
L, R = R, L
for i in range(N):
if C1[i] > 0 and C2[i] > 0:
mn = min(C1[i], C2[i])
C1[i] -= mn
C2[i] -= mn
r = 0
for i in range(N):
while R - L > 2 * r and C2[i] > 1:
r += 1
C2[i] -= 2
r += (R - L) // 2 - r
r += (sum(C1) + sum(C2)) // 2
print(r)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
t = list(map(int, input().split()))
lc = [0] * (n + 1)
rc = [0] * (n + 1)
for i in range(1, n + 1):
if i <= l:
lc[t[i - 1]] += 1
else:
rc[t[i - 1]] += 1
for i in range(1, n + 1):
mn = min(lc[i], rc[i])
lc[i] -= mn
rc[i] -= mn
l -= mn
r -= mn
if l < r:
l, r = r, l
lc, rc = rc, lc
ans = 0
for i in range(1, n + 1):
extra = l - r
can = lc[i] // 2
do = min(2 * can, extra)
ans += do // 2
l -= do
ans += (l - r) // 2 + (l + r) // 2
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
T = int(input())
t = 1
while t <= T:
n, l, r = map(int, input().split())
arr = list(map(int, input().split()))
dic1 = {}
dic2 = {}
for i in range(l):
if arr[i] not in dic1:
dic1[arr[i]] = 0
dic1[arr[i]] += 1
for j in range(l, n):
if arr[j] not in dic2:
dic2[arr[j]] = 0
dic2[arr[j]] += 1
for e in dic1:
if e in dic2:
minimum = min(dic1[e], dic2[e])
dic1[e] -= minimum
dic2[e] -= minimum
lefttot = 0
leftodd = 0
righttot = 0
rightodd = 0
for e in dic1:
if dic1[e] > 0:
if dic1[e] % 2 == 1:
leftodd += 1
lefttot += dic1[e]
for e in dic2:
if dic2[e] > 0:
if dic2[e] % 2 == 1:
rightodd += 1
righttot += dic2[e]
if lefttot <= righttot:
color = lefttot
extra = max(0, rightodd - color)
direc = (righttot - lefttot) // 2
else:
color = righttot
extra = max(0, leftodd - color)
direc = (lefttot - righttot) // 2
ans = color + extra // 2 + direc
print(ans)
t += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR FOR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
import sys
def solve(n, l, r, arr):
cnt = [(0) for i in range(n)]
if l < r:
l, r = r, l
arr = arr[r:] + arr[:r]
for i, c in enumerate(arr):
if i < l:
cnt[c - 1] += 1
else:
cnt[c - 1] -= 1
a = 0
for c in cnt:
if c > 0:
a += c // 2
return sum(max(c, 0) for c in cnt) - min(a, (l - r) // 2)
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
n, l, r = map(int, input().split())
arr = list(map(int, input().split()))
print(solve(n, l, r, arr))
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
def answer():
rc = [0] * (n + 1)
lc = [0] * (n + 1)
for i in range(n):
if i < l:
lc[a[i]] += 1
else:
rc[a[i]] += 1
v = n // 2
left = max(0, v - l) + max(0, v - r)
for i in range(n + 1):
m = min(rc[i], lc[i])
rc[i] -= m
lc[i] -= m
ans, extra = 0, 0
for i in range(n + 1):
if l > r:
v = min(lc[i] // 2, left)
ans += v
left -= v
lc[i] -= 2 * v
extra += lc[i] + rc[i]
else:
v = min(rc[i] // 2, left)
ans += v
left -= v
rc[i] -= 2 * v
extra += lc[i] + rc[i]
return ans + extra // 2 + left
for T in range(int(input())):
n, l, r = map(int, input().split())
a = list(map(int, input().split()))
print(answer())
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
while t:
n, l, r = map(int, input().split())
a = list(map(int, input().split()))
p = max(a)
d1 = {}
d2 = {}
for i in range(0, p + 1):
d1[i] = 0
d2[i] = 0
for i in range(0, l):
d1[a[i]] += 1
for i in range(0, r):
d2[a[l + i]] += 1
if r == l:
for i in d1.keys():
if d2[i] > 0 and d1[i] > 0:
x = min(d1[i], d2[i])
d1[i] -= x
d2[i] -= x
count = 0
for i in d1.keys():
count += d1[i]
print(count)
elif r > l:
diff = r - l
for i in d1.keys():
if d2[i] > 0 and d1[i] > 0:
x = min(d1[i], d2[i])
d1[i] -= x
d2[i] -= x
count = 0
for i in d2.keys():
if diff == 0:
break
temp = d2[i] // 2
if temp >= diff // 2:
count = count + diff // 2
d2[i] = d2[i] - diff
diff = 0
else:
count = count + temp
d2[i] = d2[i] - temp * 2
diff = diff - temp * 2
count = count + diff // 2
c = 0
for i in d1.keys():
c += d1[i]
for i in d2.keys():
c += d2[i]
count = count + c // 2
print(count)
elif l > r:
diff = l - r
for i in d1.keys():
if d2[i] > 0 and d1[i] > 0:
x = min(d1[i], d2[i])
d1[i] -= x
d2[i] -= x
count = 0
for i in d1.keys():
if diff == 0:
break
temp = d1[i] // 2
if temp >= diff // 2:
count = count + diff // 2
d1[i] = d1[i] - diff
diff = 0
else:
count = count + temp
d1[i] = d1[i] - temp * 2
diff = diff - temp * 2
count = count + diff // 2
c = 0
for i in d1.keys():
c += d1[i]
for i in d2.keys():
c += d2[i]
count = count + c // 2
print(count)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for z in range(int(input())):
n, l, r = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dl = {}
dr = {}
for i in range(l):
if arr[i] not in dl:
dl[arr[i]] = []
dl[arr[i]].append(i)
for i in range(l, n):
if arr[i] not in dr:
dr[arr[i]] = []
dr[arr[i]].append(i)
templ = n - r
tempr = n - l
for i in range(l):
if arr[i] in dr:
templ -= 1
tempr -= 1
temp1 = dl[arr[i]]
temp2 = dr[arr[i]]
del temp1[0]
del temp2[0]
if len(temp1) == 0:
del dl[arr[i]]
else:
dl[arr[i]] = temp1
if len(temp2) == 0:
del dr[arr[i]]
else:
dr[arr[i]] = temp2
ans = 0
if templ > tempr:
for i in dl:
tem = dl[i]
while len(tem) >= 2 and templ > tempr:
del tem[0]
del tem[0]
templ -= 2
ans += 1
if templ > tempr:
ans += templ - tempr
templ = tempr
else:
for i in dr:
tem = dr[i]
while len(tem) >= 2 and tempr > templ:
del tem[0]
del tem[0]
tempr -= 2
ans += 1
if tempr > templ:
ans += tempr - templ
tempr = templ
ans += templ
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = list(map(int, input().split()))
ar = list(map(int, input().split()))
rem, a, b = n, [0] * (n + 1), [0] * (n + 1)
for i in range(l):
a[ar[i]] += 1
for i in range(l, n):
b[ar[i]] += 1
for i in range(1, n + 1):
x = min(a[i], b[i])
a[i], b[i] = a[i] - x, b[i] - x
rem -= 2 * x
if r < l:
l, r = r, l
a, b = b, a
mx, t = sum([(b[i] // 2) for i in range(1, n + 1)]), (r - l) // 2
print((rem - 2 * min(t, mx)) // 2 + t)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
from sys import stdin, stdout
input = stdin.readline
def im():
return map(int, input().split())
def ii():
return int(input())
def il():
return list(map(int, input().split()))
def ins():
return input()[:-1]
for _ in range(ii()):
n, l, r = im()
lis = il()
left = lis[:l]
right = lis[l:]
ldic = [0] * (n + 1)
rdic = [0] * (n + 1)
for i in left:
ldic[i] += 1
for i in right:
rdic[i] += 1
for i in left:
if ldic[i] > 0 and rdic[i] > 0:
mi = min(ldic[i], rdic[i])
ldic[i] -= mi
rdic[i] -= mi
l -= mi
r -= mi
count = 0
while True:
if l == r:
stdout.write(str(count + l) + "\n")
break
elif l < r:
flag = 0
for i in range(len(rdic)):
if rdic[i] > 1:
cnt = min(rdic[i] // 2, (r - l) // 2)
rdic[i] -= cnt * 2
count += cnt
r -= cnt * 2
flag = 1
if l == r:
break
if flag == 0:
cnt = (r - l) // 2
count += cnt
l += cnt
r -= cnt
else:
flag = 0
for i in range(len(ldic)):
if ldic[i] > 1:
cnt = min(ldic[i] // 2, (l - r) // 2)
ldic[i] -= cnt * 2
count += cnt
l -= cnt * 2
flag = 1
if l == r:
break
if flag == 0:
cnt = (l - r) // 2
count += cnt
r += cnt
l -= cnt
|
ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
def solve():
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
lc = [0] * (n + 1)
rc = [0] * (n + 1)
res = 0
for i in range(l):
lc[c[i]] += 1
for i in range(l, n):
rc[c[i]] += 1
for i in range(n):
d = min(lc[i], rc[i])
lc[i] -= d
rc[i] -= d
for i in range(n + 1):
if lc[i] > rc[i]:
if l > r:
d = (l - r) // 2
give = min((lc[i] - rc[i]) // 2, d)
rc[i] += give
lc[i] -= give
l -= give
r += give
res += give
elif r > l:
d = (r - l) // 2
give = min((rc[i] - lc[i]) // 2, d)
r -= give
l += give
rc[i] -= give
lc[i] += give
res += give
res += abs(r - l) // 2
d = 0
for i in range(n + 1):
d += abs(lc[i] - rc[i])
res += d // 2 + int(d % 2 == 1)
print(res)
def main():
for _ in range(int(input())):
solve()
main()
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
t = int(input())
for i in range(t):
n, l, r = map(int, input().split())
z = list(map(int, input().split()))
left_col = z[:l]
right_col = z[l:]
d1 = {}
d2 = {}
for j in range(1, n + 1):
d1[j] = 0
d2[j] = 0
for j in range(len(left_col)):
d1[left_col[j]] += 1
for j in range(len(right_col)):
d2[right_col[j]] += 1
cnt = 0
if l == r:
for j in range(1, n + 1):
qa = min(d1[j], d2[j])
d1[j] -= qa
d2[j] -= qa
cnt += d1[j] + d2[j]
money = cnt // 2
elif l > r:
spl = 0
for j in range(1, n + 1):
qa = min(d1[j], d2[j])
d1[j] -= qa
d2[j] -= qa
cnt += d1[j] + d2[j]
if d1[j] > 1:
spl += d1[j] // 2
if spl <= (l - r) // 2:
money = (l - r) // 2 + cnt // 2 - spl
else:
money = cnt // 2
else:
spl = 0
for j in range(1, n + 1):
qa = min(d1[j], d2[j])
d1[j] -= qa
d2[j] -= qa
cnt += d1[j] + d2[j]
if d2[j] > 1:
spl += d2[j] // 2
if spl <= (r - l) // 2:
money = (r - l) // 2 + cnt // 2 - spl
else:
money = cnt // 2
print(money)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
total = 6
left = 3
right = 3
arr = [1, 2, 3, 1, 5, 6]
def answer(total, left, right, arr):
dp_left = [(0) for i in range(total)]
dp_right = [(0) for i in range(total)]
i = 0
while i < left:
dp_left[arr[i] - 1] += 1
i += 1
while i < len(arr):
dp_right[arr[i] - 1] += 1
i += 1
left1 = 0
right1 = 0
for i in range(total):
if dp_left[i] >= 1 and dp_right[i] >= 1:
m = min(dp_left[i], dp_right[i])
dp_left[i] -= m
dp_right[i] -= m
left1 += dp_left[i]
right1 += dp_right[i]
else:
left1 += dp_left[i]
right1 += dp_right[i]
cost = 0
mid = (left1 + right1) // 2
if left1 > mid:
cost += left1 - mid
for i in range(total):
if dp_left[i] >= 2:
k = dp_left[i] // 2
if left1 - 2 * k > right1:
left1 -= 2 * k
elif left1 - 2 * k == right1:
left1 -= 2 * k
break
else:
p = right1 - (left1 - 2 * k)
left1 -= p
break
if right1 > mid:
cost += right1 - mid
for i in range(total):
if dp_right[i] >= 2:
k = dp_right[i] // 2
if right1 - 2 * k > left1:
right1 -= 2 * k
elif right1 - 2 * k == left1:
right1 -= 2 * k
break
else:
p = left1 - (right1 - 2 * k)
right1 -= p
break
cost += (left1 + right1) // 2
print(cost)
t = int(input())
for w in range(t):
inp = input().split()
total = int(inp[0])
left = int(inp[1])
right = int(inp[2])
inp = input().split()
arr = []
for i in inp:
arr.append(int(i))
answer(total, left, right, arr)
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
|
To satisfy his love of matching socks, Phoenix has brought his $n$ socks ($n$ is even) to the sock store. Each of his socks has a color $c_i$ and is either a left sock or right sock.
Phoenix can pay one dollar to the sock store to either:
recolor a sock to any color $c'$ $(1 \le c' \le n)$
turn a left sock into a right sock
turn a right sock into a left sock
The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.
A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $n/2$ matching pairs? Each sock must be included in exactly one matching pair.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) β the number of test cases.
The first line of each test case contains three integers $n$, $l$, and $r$ ($2 \le n \le 2 \cdot 10^5$; $n$ is even; $0 \le l, r \le n$; $l+r=n$) β the total number of socks, and the number of left and right socks, respectively.
The next line contains $n$ integers $c_i$ ($1 \le c_i \le n$) β the colors of the socks. The first $l$ socks are left socks, while the next $r$ socks are right socks.
It is guaranteed that the sum of $n$ across all the test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the minimum cost for Phoenix to make $n/2$ matching pairs. Each sock must be included in exactly one matching pair.
-----Examples-----
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
-----Note-----
In the first test case, Phoenix can pay $2$ dollars to:
recolor sock $1$ to color $2$
recolor sock $3$ to color $2$
There are now $3$ matching pairs. For example, pairs $(1, 4)$, $(2, 5)$, and $(3, 6)$ are matching.
In the second test case, Phoenix can pay $3$ dollars to:
turn sock $6$ from a right sock to a left sock
recolor sock $3$ to color $1$
recolor sock $4$ to color $1$
There are now $3$ matching pairs. For example, pairs $(1, 3)$, $(2, 4)$, and $(5, 6)$ are matching.
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
c = list(map(int, input().split()))
sockc = [0] * (n + 1)
cost = 0
for i in range(l):
sockc[c[i]] += 1
for i in range(l, n):
sockc[c[i]] -= 1
pos = 0
neg = 0
posodd = 0
negodd = 0
for i in range(n + 1):
if sockc[i] > 0:
pos += sockc[i]
posodd += sockc[i] % 2
elif sockc[i] < 0:
neg += -sockc[i]
sockc[i] = -sockc[i]
negodd += sockc[i] % 2
if pos == neg:
print(pos)
elif pos > neg:
if posodd > neg:
posodd -= neg
print(posodd + (pos + neg - posodd) // 2)
else:
print((pos + neg) // 2)
else:
t = pos
pos = neg
neg = t
posodd = negodd
if posodd > neg:
posodd -= neg
print(posodd + (pos + neg - posodd) // 2)
else:
print((pos + neg) // 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
count = 0
i = 0
j = n // 2
while i < n // 2 and j < n:
if x[j] - x[i] >= z:
count += 1
i += 1
j += 1
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
N, Z = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
def compute(x1, x2):
count = 0
i = 0
j = 0
while i < len(x1) and j < len(x2):
while x2[j] - x1[i] < Z:
j += 1
if j == len(x2):
return count
count += 1
i += 1
j += 1
return count
if N % 2 == 0:
print(compute(X[0 : N // 2], X[N // 2 :]))
else:
v1 = compute(X[0 : N // 2], X[N // 2 :])
v2 = compute(X[0 : N // 2 + 1], X[N // 2 + 1 :])
print(max(v1, v2))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
k = n // 2
s = 0
mas = [0] * n
for i in range(n):
if mas[i] == 1:
continue
for j in range(k, n):
if a[j] - a[i] >= m and mas[j] != 1:
mas[i] = 1
mas[j] = 1
k = j + 1
s += 1
break
if j == n - 1:
print(s)
exit()
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
_, z = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
pos = -1
for i in range(len(p) // 2, len(p)):
if p[i] >= p[0] + z:
pos = i
break
if pos == -1:
print(0)
else:
r = pos
l = 0
ctr = 0
while True:
if l == pos:
break
if r == len(p):
break
if p[r] >= p[l] + z:
ctr += 1
r += 1
l += 1
else:
r += 1
print(ctr)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
x, y = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
j = len(a) // 2
count = 0
while j < len(a):
if abs(a[i] - a[j]) >= y:
count += 1
a[i] = -1
a[j] = -1
else:
j += 1
while i < len(a) and a[i] == -1:
i += 1
while j < len(a) and (a[j] == -1 or j <= i):
j += 1
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
vis = [False] * n
j = n // 2
for i in range(n // 2):
if vis[i]:
continue
while j < n and A[j] - A[i] < z:
j += 1
if j == n:
break
vis[j] = True
j += 1
ans += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
from sys import stdin, stdout
def main():
from sys import stdin, stdout
def read():
return stdin.readline().rstrip("\n")
def read_array(sep=None, maxsplit=-1):
return read().split(sep, maxsplit)
def read_int():
return int(read())
def read_int_array(sep=None, maxsplit=-1):
return [int(a) for a in read_array(sep, maxsplit)]
def write(*args, **kwargs):
sep = kwargs.get("sep", " ")
end = kwargs.get("end", "\n")
stdout.write(sep.join(str(a) for a in args) + end)
def write_array(array, **kwargs):
sep = kwargs.get("sep", " ")
end = kwargs.get("end", "\n")
stdout.write(sep.join(str(a) for a in array) + end)
n, z = read_int_array()
nums = read_int_array()
nums.sort()
out = 0
used = [False] * n
i, j = 0, len(nums) // 2
while i < n:
used[i] = True
while j < n and (used[j] or nums[j] - nums[i] < z):
j += 1
if j == n:
break
used[j] = True
while i < n and used[i]:
i += 1
out += 1
write(out)
main()
|
FUNC_DEF FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF NONE NUMBER RETURN FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NONE NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
taken = [0] * n
r = n // 2
ans = 0
for i in range(n):
if taken[i]:
continue
while r < n and A[r] - A[i] < x:
r += 1
while r < n and taken[r]:
r += 1
if r < n and A[r] - A[i] >= x:
taken[r] = 1
ans += 1
r += 1
taken[i] = 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
li = sorted(list(map(int, input().split())))
i, j = 0, n // 2
count = 0
n = len(li)
while i < n // 2 and j < n:
if li[j] - li[i] >= z:
count += 1
i += 1
j += 1
else:
j += 1
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
c = 0
l = 0
r = len(arr) // 2
while r < len(arr) and l < len(arr):
if arr[l] == -1:
l += 1
continue
if arr[r] - arr[l] >= z and arr[r] != -1:
arr[r] = -1
c += 1
r += 1
l += 1
else:
r += 1
print(c)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
arr = sorted(map(int, input().split()))
i, j, count = 0, n // 2, 0
while i < n // 2 and j < n:
if arr[i] + z <= arr[j]:
count += 1
i += 1
j += 1
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
res = 0
def can_match(k):
if 2 * k > n:
return False
if k == 0:
return True
b = a[:]
j = k
for i in range(n):
if b[i] != -1:
while j < n and (j <= i or b[j] == -1 or b[j] < b[i] + z):
j += 1
if j < n:
b[i] = -1
b[j] = -1
k -= 1
if k == 0:
return True
else:
break
return False
l, r = 0, n
while l < r:
m = (l + r) // 2
if can_match(m):
l = m + 1
else:
r = m
print(l - 1)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
beg = n // 2
cnt = 0
for i in range(n // 2):
low = beg
high = n - 1
while low < high:
mid = (low + high) // 2
if lst[mid] - lst[i] >= z:
high = mid
elif lst[mid] - lst[i] < z:
low = mid + 1
if low == n - 1:
if lst[low] - lst[i] >= z:
cnt = cnt + 1
break
beg = low + 1
cnt = cnt + 1
print(cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = a[: n // 2]
a = a[n // 2 :]
i = 0
j = 0
ans = 0
while i < len(b) and j < len(a):
if a[j] - b[i] >= z:
ans += 1
i += 1
j += 1
else:
j += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = [int(i) for i in input().split(" ")]
nums = [int(i) for i in input().split(" ")]
nums.sort()
if n % 2 == 0:
odd = nums[: n // 2]
even = nums[n // 2 :]
else:
odd = nums[: n // 2]
even = nums[n // 2 + 1 :]
i, j = 0, 0
res = 0
while i < len(odd) and j < len(even):
if abs(odd[i] - even[j]) >= z:
res += 1
i += 1
j += 1
else:
j += 1
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, m = map(int, input().split())
li = [int(k) for k in input().split()]
mark = [0] * n
i = 0
j = n // 2
li.sort()
ans = 0
while i < n and j < n:
if i != j and li[j] - li[i] >= m and mark[i] == 0 and mark[j] == 0:
ans += 1
mark[i] = 1
mark[j] = 1
i += 1
j += 1
elif li[j] - li[i] < m:
if mark[i] == 1 and mark[j] == 0:
i += 1
elif mark[j] == 1 and mark[i] == 0:
j += 1
elif mark[j] == 1 and mark[i] == 1:
i += 1
j += 1
elif mark[j] == 0 and mark[i] == 0:
j += 1
elif li[j] - li[i] >= m:
if mark[i] == 1 and mark[j] == 0:
i += 1
elif mark[j] == 1 and mark[i] == 0:
j += 1
elif mark[j] == 1 and mark[i] == 1:
i += 1
j += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def li():
return list(map(int, input().split()))
def num():
return map(int, input().split())
def nu():
return int(input())
def solve():
t = 1
for _ in range(t):
n, z = num()
a = li()
a.sort()
cc = 0
l = 0
end = n // 2
while l <= end:
mid = (l + end) // 2
fl = True
for i in range(mid):
if a[n - mid + i] - a[i] < z:
fl = False
break
if fl:
l = mid + 1
else:
end = mid - 1
print(end)
solve()
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
s = sorted(list(map(int, input().split())))
q = [(True) for n in range(n)]
rt = 0
i = 0
j = n // 2
while i < n and j < n:
while j < n and s[i] + z > s[j]:
j += 1
if i < j < n and q[i] and q[j]:
q[i] = False
q[j] = False
rt += 1
i += 1
j += 1
print(rt)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
def can(x, c):
for a, b in zip(x[:c], x[-c:]):
if a + z > b:
return False
return True
x = [int(x) for x in input().split()]
x.sort()
l = 0
r = n // 2 + 1
while r - l > 1:
mid = (l + r) // 2
if can(x, mid):
l = mid
else:
r = mid
print(l)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = list(map(int, input().split()))
l = list(map(int, input().split()))
l = sorted(l)
wyn = 0
maly = 0
duzy = n // 2
zaj = [0] * n
while duzy < n:
while maly < n:
if zaj[maly] == 1:
maly += 1
else:
break
if l[duzy] - l[maly] >= z and zaj[duzy] == 0 and zaj[maly] == 0:
wyn += 1
maly += 1
zaj[maly - 1] = 1
zaj[duzy] = 1
duzy += 1
print(wyn)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
N, Z = list(map(int, input().split()))
A = sorted([int(a) for a in input().split()])
l, r = 0, N // 2 + 1
while r - l > 1:
m = (r + l) // 2
for i in range(m):
if A[N - m + i] - A[i] < Z:
r = m
break
else:
l = m
print(l)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
nzint = input().split()
nz = [int(x) for x in nzint]
input_string = input().split()
intlist = [int(x) for x in input_string]
intlist.sort()
i, j = nz[0] - 1, nz[0] // 2 - 1
count = 0
while i >= nz[0] // 2 - 1 and j >= 0:
if intlist[i] - intlist[j] >= nz[1]:
count = count + 1
i = i - 1
j = j - 1
print(count)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, x = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
nums.sort()
left = 0
right = n + 1
count = 0
while True:
if right - left <= 1 or right <= (n + 1) // 2:
break
c = 0
ok = True
mid = int((left + right) / 2)
for i in range(n - mid):
if nums[mid + i] - nums[i] >= x:
c += 1
else:
ok = False
break
if not ok:
left = mid
else:
right = mid
if c > count:
count = c
ok = True
c = 0
for i in range(n - left):
if nums[left + i] - nums[i] >= x:
c += 1
else:
ok = False
break
if ok:
if c > count and c <= (n + 1) // 2:
count = c
ok = True
c = 0
for i in range(n - right):
if nums[right + i] - nums[i] >= x:
c += 1
else:
ok = False
break
if ok:
if c > count and c <= (n + 1) // 2:
count = c
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = [int(x) for x in input().split()]
b = sorted([int(x) for x in input().split()])
a = []
for item in b:
a.append([item, 0])
end = n // 2
counter = 0
for i in range(n):
if end == i:
end += 1
for j in range(end, n):
if a[j][0] - a[i][0] >= z and a[j][1] == a[i][1] == 0:
end = j
counter += 1
a[i][1] = a[j][1] = 1
break
else:
end = j
print(counter)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
l = n // 2 - 1
r = n - 1
m = (l + r) // 2
cnt = 0
for i in range(l, -1, -1):
if X[r] - X[l] >= z:
cnt += 1
l -= 1
r -= 1
else:
l -= 1
print(cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def check(num):
first = l[0:num]
second = l[n - num : n]
for i in range(num):
if second[i] - first[i] < m:
return False
return True
n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
low = 0
high = n // 2
while low < high:
mid = (low + high) // 2
if check(mid):
low = mid + 1
else:
high = mid - 1
if check(low):
print(low)
else:
print(low - 1)
|
FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def ans(array, z):
array.sort()
left = 0
right = n // 2 + 1
while right - left > 1:
mid = (left + right) // 2
good = True
for i in range(mid):
good &= array[n - mid + i] - array[i] >= z
if good:
left = mid
else:
right = mid
return left
n, z = map(int, input().split())
a = list(map(int, input().split()))
print(ans(a, z))
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
def solve():
n, z = nm()
a = sorted(nm())
ok, ng = 0, n // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
p = a[:mid]
q = a[-mid:]
for y, x in zip(q, p):
if y - x < z:
ng = mid
break
else:
ok = mid
print(ok)
return
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
a = [int(x) for x in input().split()]
A = sorted(a)
A.sort()
a = 0
b = n // 2
while a < b:
mid = (a + b + 1) // 2
if all(A[-mid + ind] - A[ind] >= z for ind in range(mid)):
a = mid
else:
b = mid - 1
print(a)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if len(a) % 2 == 0:
x = len(a) // 2
else:
x = len(a) // 2 + 1
i = 0
while x < len(a):
if a[x] - a[i] >= k:
i += 1
x += 1
print(i)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def maxpairs(ls, mdiff):
cou = 0
ls.sort()
id2 = int(len(ls) / 2)
for i in range(len(ls) // 2):
flag = True
cp_i = ls[i]
while id2 <= len(ls) - 1:
flag = False
if cp_i + mdiff <= ls[id2]:
cou += 1
id2 += 1
break
id2 += 1
if flag:
break
return cou
a, mdiff = map(int, input().split())
ls = list(map(int, input().strip().split()))
print(maxpairs(ls, mdiff))
|
FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, k = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
def check(mi):
try:
if 2 * mi > n:
return 0
l1 = [l[i] for i in range(mi)]
l2 = [l[i] for i in range(n - mi, n)]
for i in range(mi):
if l1[i] + k > l2[i]:
return 0
return 1
except:
return 0
lo = 1
hi = n // 2
ans = 0
while lo <= hi:
mi = lo + hi >> 1
if check(mi):
ans = mi
lo = mi + 1
else:
hi = mi - 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
import sys
input = sys.stdin.readline
n, z = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
def match(cut):
i = 0
j = cut
ANS = 0
for i in range(cut):
while j < n and X[j] - X[i] < z:
j += 1
if j == n:
break
else:
ANS += 1
j += 1
return ANS
MIN = 1
MAX = n - 1
while MAX - MIN > 1:
MID0 = (MIN + MAX) // 2 - 1
MID1 = (MIN + MAX) // 2
ANS2 = match(MID0)
ANS3 = match(MID1)
if ANS2 == ANS3:
print(ANS2)
return
if ANS2 > ANS3:
MAX = MID0
else:
MIN = MID1
print(max(match(MIN), match(MAX)))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def find(A, z):
def check(k, z):
L = A[:k]
R = A[-k:]
for i in range(len(L)):
if abs(L[i] - R[i]) >= z:
continue
else:
return False
return True
A = sorted(A)
left = 0
right = len(A) // 2
while right - left > 1:
mid = (left + right) // 2
if check(mid, z):
left = mid
else:
right = mid
if check(left + 1, z):
return left + 1
else:
return left
n, z = list(map(int, input().strip().split(" ")))
A = list(map(int, input().strip().split(" ")))
print(find(A, z))
|
FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
taken = [0] * n
lo = 0
hi = n // 2 + 1
def check(sz):
if sz > n // 2:
return 0
left = A[:sz]
right = A[-sz:]
ok = 1
for i in range(len(left)):
if right[i] - left[i] >= x:
continue
else:
ok = 0
return ok
for i in range(200):
mid = (lo + hi) // 2
if check(mid):
lo = mid
else:
hi = mid
ans = 0
for i in range(max(0, lo - 5), min(hi + 5, n // 2)):
if check(i):
ans = i
else:
break
print(mid)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
arrs = [int(x) for x in input().split()]
arrs.sort()
def fi():
j = len(arrs) // 2
while arrs[j] - arrs[0] < z and j < len(arrs) - 1:
j += 1
l = 0
r = j
arr = arrs[:]
cnt = 0
while r != len(arr):
if arr[l] == 10**10:
l += 1
elif arr[r] - arr[l] >= z:
arr[r] = 10**10
cnt += 1
r += 1
l += 1
else:
r += 1
return cnt
print(fi())
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def max_pairs(arr, z):
count = 0
N = len(arr)
arr.sort()
i = 0
mid = N // 2 + (1 if N % 2 else 0)
j = mid
while i < mid and j < N:
while j < N and arr[j] - arr[i] < z:
j += 1
if j != N:
count += 1
i += 1
j += 1
return count
def main():
n, z = map(int, input().split())
arr = [int(i) for i in input().split()]
print(max_pairs(arr, z))
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = [0] + arr
s_arr = sorted(arr)
f_arr = [1] * (n + 1)
l = 1
r = int((n + 1) / 2) + 1
cnt = 0
while r <= n and l <= r:
if s_arr[r] - s_arr[l] >= z:
cnt += 1
l += 1
r += 1
print(cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
cnt = 0
begin = len(lst) // 2
for i in range(len(lst) // 2):
if begin > len(lst) - 1:
break
elif lst[begin] - lst[i] >= z:
cnt = cnt + 1
begin = begin + 1
continue
else:
while begin <= len(lst) - 1:
if lst[begin] - lst[i] >= z:
cnt = cnt + 1
begin = begin + 1
break
else:
begin = begin + 1
print(cnt)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
n, z = map(int, input().split())
x = sorted(list(map(int, input().split())))
ost = []
number = 0
for i in range(n // 2):
ost.append(x[i])
j = 0
length = len(ost)
for i in range(n // 2, n):
if j < length and x[i] - x[j] >= z:
j += 1
number += 1
print(number)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def __starting_point():
n, z = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mask = [(0) for i in range(n)]
start = int((n - 1) / 2)
end = n - 1
res = 0
while end >= 0:
if abs(a[start] - a[end]) >= z and mask[end] == 0 and mask[start] == 0:
mask[start] = 1
mask[end] = 1
start -= 1
end -= 1
res += 1
elif mask[start] == 1:
start -= 1
elif mask[end] == 1:
end -= 1
else:
start -= 1
if start < 0:
break
print(res)
__starting_point()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.
Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$.
What is the maximum number of pairs of points you can match with each other?
-----Input-----
The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) β the number of points and the constraint on the distance between matched points, respectively.
The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).
-----Output-----
Print one integer β the maximum number of pairs of points you can match with each other.
-----Examples-----
Input
4 2
1 3 3 7
Output
2
Input
5 5
10 9 5 8 7
Output
1
-----Note-----
In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).
In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).
|
def solve():
n, z = [int(s) for s in input().split(" ")]
x = [int(s) for s in input().split(" ")]
x.sort()
def good(k):
if 2 * k > n:
return False
for i in range(k):
if x[-(k - i)] - x[i] < z:
return False
return True
l = 0
r = n
while r - l > 1:
m = (l + r) // 2
if good(m):
l = m
else:
r = m
return l
print(solve())
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.