description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given a graph with $3 \cdot n$ vertices and $m$ edges. You are to find a matching of $n$ edges, or an independent set of $n$ vertices.
A set of edges is called a matching if no two edges share an endpoint.
A set of vertices is called an independent set if no two vertices are connected with an edge.
-----Input-----
The first line contains a single integer $T \ge 1$ — the number of graphs you need to process. The description of $T$ graphs follows.
The first line of description of a single graph contains two integers $n$ and $m$, where $3 \cdot n$ is the number of vertices, and $m$ is the number of edges in the graph ($1 \leq n \leq 10^{5}$, $0 \leq m \leq 5 \cdot 10^{5}$).
Each of the next $m$ lines contains two integers $v_i$ and $u_i$ ($1 \leq v_i, u_i \leq 3 \cdot n$), meaning that there is an edge between vertices $v_i$ and $u_i$.
It is guaranteed that there are no self-loops and no multiple edges in the graph.
It is guaranteed that the sum of all $n$ over all graphs in a single test does not exceed $10^{5}$, and the sum of all $m$ over all graphs in a single test does not exceed $5 \cdot 10^{5}$.
-----Output-----
Print your answer for each of the $T$ graphs. Output your answer for a single graph in the following format.
If you found a matching of size $n$, on the first line print "Matching" (without quotes), and on the second line print $n$ integers — the indices of the edges in the matching. The edges are numbered from $1$ to $m$ in the input order.
If you found an independent set of size $n$, on the first line print "IndSet" (without quotes), and on the second line print $n$ integers — the indices of the vertices in the independent set.
If there is no matching and no independent set of the specified size, print "Impossible" (without quotes).
You can print edges and vertices in any order.
If there are several solutions, print any. In particular, if there are both a matching of size $n$, and an independent set of size $n$, then you should print exactly one of such matchings or exactly one of such independent sets.
-----Example-----
Input
4
1 2
1 3
1 2
1 2
1 3
1 2
2 5
1 2
3 1
1 4
5 1
1 6
2 15
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6
Output
Matching
2
IndSet
1
IndSet
2 4
Matching
1 15
-----Note-----
The first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.
The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5: 2 3 4 5 6. However such answer is not correct, because you are asked to find an independent set (or matching) of size exactly $n$.
The fourth graph does not have an independent set of size 2, but there is a matching of size 2.
|
from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(T):
n, m = [int(i) for i in input().split()]
ind_edg_v = [True] * (3 * n + 1)
ind_edg_e = [0] * n
num_edg = 0
for j in range(m):
edge_0, edge_1 = [int(i) for i in input().split()]
if num_edg < n:
if ind_edg_v[edge_0] and ind_edg_v[edge_1]:
ind_edg_e[num_edg] = j + 1
ind_edg_v[edge_0], ind_edg_v[edge_1] = False, False
num_edg += 1
if num_edg == n:
print("Matching")
print(" ".join([str(i) for i in ind_edg_e]))
else:
print("IndSet")
vertex = 0
for i in range(n):
vertex += 1
while not ind_edg_v[vertex]:
vertex += 1
print(vertex, end=" ")
print()
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a graph with $3 \cdot n$ vertices and $m$ edges. You are to find a matching of $n$ edges, or an independent set of $n$ vertices.
A set of edges is called a matching if no two edges share an endpoint.
A set of vertices is called an independent set if no two vertices are connected with an edge.
-----Input-----
The first line contains a single integer $T \ge 1$ — the number of graphs you need to process. The description of $T$ graphs follows.
The first line of description of a single graph contains two integers $n$ and $m$, where $3 \cdot n$ is the number of vertices, and $m$ is the number of edges in the graph ($1 \leq n \leq 10^{5}$, $0 \leq m \leq 5 \cdot 10^{5}$).
Each of the next $m$ lines contains two integers $v_i$ and $u_i$ ($1 \leq v_i, u_i \leq 3 \cdot n$), meaning that there is an edge between vertices $v_i$ and $u_i$.
It is guaranteed that there are no self-loops and no multiple edges in the graph.
It is guaranteed that the sum of all $n$ over all graphs in a single test does not exceed $10^{5}$, and the sum of all $m$ over all graphs in a single test does not exceed $5 \cdot 10^{5}$.
-----Output-----
Print your answer for each of the $T$ graphs. Output your answer for a single graph in the following format.
If you found a matching of size $n$, on the first line print "Matching" (without quotes), and on the second line print $n$ integers — the indices of the edges in the matching. The edges are numbered from $1$ to $m$ in the input order.
If you found an independent set of size $n$, on the first line print "IndSet" (without quotes), and on the second line print $n$ integers — the indices of the vertices in the independent set.
If there is no matching and no independent set of the specified size, print "Impossible" (without quotes).
You can print edges and vertices in any order.
If there are several solutions, print any. In particular, if there are both a matching of size $n$, and an independent set of size $n$, then you should print exactly one of such matchings or exactly one of such independent sets.
-----Example-----
Input
4
1 2
1 3
1 2
1 2
1 3
1 2
2 5
1 2
3 1
1 4
5 1
1 6
2 15
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6
Output
Matching
2
IndSet
1
IndSet
2 4
Matching
1 15
-----Note-----
The first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.
The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5: 2 3 4 5 6. However such answer is not correct, because you are asked to find an independent set (or matching) of size exactly $n$.
The fourth graph does not have an independent set of size 2, but there is a matching of size 2.
|
import sys
input = sys.stdin.readline
T = int(input())
for testcases in range(T):
n, m = map(int, input().split())
EDGE = [[0, 0]] + [list(map(int, input().split())) for i in range(m)]
USED = [0] * (3 * n + 1)
count = 0
ANS = []
for i in range(1, m + 1):
x, y = EDGE[i]
if USED[x] == 0 and USED[y] == 0:
count += 1
ANS.append(i)
USED[x] = 1
USED[y] = 1
if count == n:
print("Matching")
print(*ANS)
break
else:
ANS = []
count = 0
for i in range(1, 3 * n + 1):
if USED[i] == 0:
count += 1
ANS.append(i)
if count == n:
print("IndSet")
print(*ANS)
break
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
import sys
k = int(sys.stdin.readline().split()[1])
t = list(map(lambda s: int(s), sys.stdin.readline().split()))
t.sort()
def find(x, a, b):
while True:
if a == b:
if x == t[a]:
return a
else:
return None
m = a + (b - a) // 2
if x > t[m]:
a = m + 1
else:
b = m
u = [(True) for i in t]
s = 0
for i in range(len(t)):
if u[i]:
s += 1
u[i] = False
j = find(t[i] * k, 0, len(t) - 1)
if j is not None:
u[j] = False
print(s)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF WHILE NUMBER IF VAR VAR IF VAR VAR VAR RETURN VAR RETURN NONE ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
p = []
a = sorted(l)
for i in a:
if i % k == 0:
if i // k in p:
pass
else:
p.append(i)
else:
p.append(i)
print(len(set(p)))
|
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 LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
d = {}
for i in arr:
if i % k == 0 and i // k in d:
d[i] = d[i // k] + 1
del d[i // k]
else:
d[i] = 1
ans = 0
for i in d:
if d[i] % 2:
ans += d[i] // 2 + 1
else:
ans += d[i] // 2
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 DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def main():
n, k = [int(x) for x in input().split(" ")]
if k == 1:
print(n)
return
a = []
b = {}
a = [int(x) for x in input().split(" ")]
a.sort()
a = dict(zip(a, range(n)))
count = {}
for x in a:
if x % k == 0 and int(x / k) in a:
b[x] = b[int(x / k)]
count[b[int(x / k)]] += 1
else:
b[x] = x
count[x] = 1
for x, y in count.items():
n -= int(y / 2)
print(n)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
lis = [0] + sorted(map(int, input().split()))
kk = lis[:]
ans = 0
for i in range(n, -1, -1):
l = 0
r = i
if kk[i] == 0:
continue
while l <= r:
mid = l + (r - l) // 2
if lis[i] / k < lis[mid]:
r = mid - 1
else:
l = mid + 1
if lis[r] * 10 == lis[i] / k * 10:
kk[r] = 0
ans += 1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def bb(A, item):
esquerda, direita = 0, len(A) - 1
while esquerda <= direita:
meio = (esquerda + direita) // 2
if A[meio] == item:
return meio
elif A[meio] > item:
direita = meio - 1
elif A[meio] < item:
esquerda = meio + 1
return -1
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
menores = []
maiores = []
for i in range(n):
if bb(menores, a[i]) == -1:
if bb(maiores, a[i]) == -1:
menores.append(a[i])
maiores.append(a[i] * k)
else:
continue
print(len(menores))
|
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
k = int(input().split()[1])
l = sorted(map(int, input().split()))
res = set()
for i in l:
if i % k != 0:
res.add(i)
elif i // k not in res:
res.add(i)
print(len(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = input().split()
n = int(n)
k = int(k)
a = [int(i) for i in input().split()]
a.sort()
mul = [0] * n
def search(a, val, k):
l = 0
r = len(a) - 1
while l <= r:
mid = (l + r) // 2
if a[mid] == val * k:
return mid
elif a[mid] > val * k:
r = mid - 1
else:
l = mid + 1
return -1
if n == 1:
print(1)
else:
count = 0
for i in range(n):
pos = search(a, a[i], k)
if pos != -1 and pos != i:
mul[pos] = mul[i] + 1
for i in range(n):
if not mul[i] % 2:
count += 1
print(count)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR RETURN VAR IF VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
a = [*map(int, input().split())]
a.sort()
def binary_search(arr, value):
first, last = 0, len(arr) - 1
while first <= last:
mid = (first + last) // 2
if arr[mid] == value:
return mid
elif arr[mid] < value:
first = mid + 1
else:
last = mid - 1
return -1
ans = 0
for i in range(n):
if a[i] != -1:
ans += 1
id = binary_search(a, a[i] * k)
if id != -1:
a[id] = -1
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def sfun(n, k, lst):
s = {}
for i in range(n):
if lst[i] * k in s:
continue
s[lst[i]] = 1
return len(s)
N, K = [int(j) for j in input().split()]
a = [int(x) for x in input().split()]
print(sfun(N, K, sorted(a, reverse=True)))
|
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
t = list(map(int, input().split()))
if k == 1:
print(len(set(t)))
else:
p = [set() for i in range(30)]
for i in t:
j = 0
while i % k == 0:
i //= k
j += 1
p[j].add(i)
for j in range(1, 30):
p[j] -= p[j - 1]
print(sum(len(i) for i in p))
|
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 IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def main():
n, k = map(int, input().split())
if n == 1:
print(1)
return
l = sorted(map(int, input().split()))
baned = set()
s = set(l)
if k > 1:
for p in l:
if p not in baned:
p *= k
s.discard(p)
baned.add(p)
print(len(s))
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def bSearch(x, li):
l = 0
h = len(li)
while l <= h:
m = (l + h) // 2
if li[m] == x:
return m
elif li[m] > x:
h = m - 1
else:
l = m + 1
return -1
n, k = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
s = set()
for i in range(n):
if li[i] % k == 0:
z = bSearch(li[i] // k, li)
if z != -1:
if li[z] not in s:
s.add(li[i])
else:
s.add(li[i])
else:
s.add(li[i])
print(len(s))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER 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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = list(map(int, input().split()))
L = list(map(int, input().split()))
L.sort(reverse=True)
S = {}
for i in range(n):
if L[i] * k in S:
continue
S[L[i]] = 1
print(len(S))
|
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 NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
p = [int(x) for x in input().split()]
s = []
p = sorted(p)
for i in range(0, n):
if p[i] % k != 0:
s.append(p[i])
elif int(p[i] / k) not in s:
s.append(p[i])
print(len(s))
|
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 LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
if k == 1:
print(n)
exit()
res = set(arr)
for x in arr:
if x in res:
res.discard(x * k)
print(len(res))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
ai = list(map(int, input().split()))
def binsearch(num):
high = n - 1
low = 0
mid = (high + low) // 2
while high >= low:
if ai[mid] < num:
low = mid + 1
elif ai[mid] > num:
high = mid - 1
else:
return mid
mid = (high + low) // 2
return -1
ai.sort()
ar = [0] * n
ans = 0
for i in range(n):
if ar[i]:
continue
num = binsearch(ai[i] * k)
if num != -1:
ar[num] = 1
ans += 1
if k == 1:
ans = 0
print(n - 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 FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
element = list(map(int, input().rstrip().split()))
element.sort()
cross = set(element)
for i in element:
if i in cross:
if i * k in cross:
cross.remove(i * k)
if k == 1:
print(len(element))
else:
print(len(cross))
|
ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
s = input().split()
n, k = int(s[0]), int(s[1])
s = input().split()
a, b = [], []
for x in s:
a.append(int(x))
b.append(0)
a.sort()
ans = n
for i in range(n):
if b[i] == -1:
continue
l, r = i + 1, n - 1
j = -1
while l < r and j == -1:
m = (l + r) // 2
if a[m] < a[i] * k:
l = m + 1
elif a[m] > a[i] * k:
r = m
else:
j = m
m = (l + r) // 2
if a[m] == a[i] * k and a[i] < a[m]:
j = m
if j != -1:
if b[j] != -1:
b[j] = -1
ans -= 1
print(ans)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
from sys import stdin
def main():
n, k = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
if k == 1:
print(n)
else:
ar.sort()
lk = set()
check = {}
for elm in ar:
lk.add(elm)
check[elm] = False
ans = 0
max_val = ar[-1]
for i in range(n):
if not check[ar[i]]:
cnt = 0
curr = ar[i]
while curr <= max_val and curr in lk:
cnt += 1
check[curr] = True
curr = curr * k
ans += cnt // 2 + cnt % 2
print(ans)
main()
|
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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort()
s = []
d = {}
m = 0
for i in a:
if i % k != 0:
s.append(i)
d[i] = 1
m += 1
elif i // k not in d:
s.append(i)
d[i] = 1
m += 1
print(m)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
a, b = map(int, input().split(" "))
ints = list(map(int, input().split(" ")))
ints.sort()
dictionary = {}
for num in ints:
if num / b % 1 != 0:
dictionary[num] = 1
elif int(num / b) not in dictionary:
dictionary[num] = 1
print(len(dictionary))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
s = set([])
ans = 0
for i in l:
if i % k == 0:
if i // k not in s:
s.add(i)
ans += 1
else:
ans += 1
s.add(i)
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 ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
r = input("").split(" ")
x = int(r[0])
y = int(r[1])
l = input("").split(" ")
l = [int(x) for x in l]
l.sort()
k = {}
r = len(l)
for g in range(len(l)):
if l[g] % y == 0:
rk = l[g] // y
if rk not in k:
k[l[g]] = 1
else:
r -= 1
else:
k[l[g]] = 1
print(r)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
t, r = {}, 0
for i in a:
if i not in t:
t[i] = 1
r += 1
if t[i]:
t[i * k] = 0
print(r)
|
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 DICT NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
from sys import stdin
def main():
inp = stdin
n, k = list(map(int, inp.readline().split()))
nums = list(map(int, inp.readline().split()))
nums.sort(reverse=True)
final = set()
for i in range(0, n):
mult = nums[i] * k
if not mult in final:
final.add(nums[i])
print(len(final))
main()
|
FUNC_DEF 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 NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
seq_set = set()
for e in sorted(int(c) for c in input().split()):
if e % k or e // k not in seq_set:
seq_set.add(e)
print(len(seq_set))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def K_multiple(a, n, k):
a.sort()
s = set()
for i in range(n):
if a[i] % k == 0 and a[i] // k not in s or a[i] % k != 0:
s.add(a[i])
print(len(s))
n, k = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
K_multiple(a, n, k)
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
class K_Free:
def __init__(self, n, k):
self.n = n
self.k = k
self.fuad = list(map(int, input().split()))
self.fuad.sort()
self.ans = []
def Solve(self):
for x in self.fuad:
if x % self.k:
self.ans.append(x)
elif int(x / self.k) not in self.ans:
self.ans.append(x)
return len(self.ans)
a, b = map(int, input().split())
obj = K_Free(a, b)
print(obj.Solve())
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, m = list(map(int, input().split()))
l = list(map(int, input().split()))
l = sorted(l)
ma = 1
d = {l[0]}
for i in range(1, n):
if l[i] / m not in d:
d.add(l[i])
ma += 1
print(ma)
|
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
exclude = set()
ans = 0
a.sort()
for i in a:
if i not in exclude:
exclude.add(i * k)
ans += 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
lol = {}
flag = {}
arr.sort()
for x in arr:
flag[x] = 1
ans = 0
for i in range(len(arr)):
if arr[i] in lol:
continue
cur = arr[i]
cnt = 0
while cur <= 1000000000:
lol[cur] = 1
if cur in flag:
cnt += 1
else:
break
cur = cur * k
if k == 1:
break
ans += (cnt + 1) // 2
print(ans)
|
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 DICT ASSIGN VAR DICT EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(n):
d[a[i]] = 1
a.sort(reverse=True)
ans = 0
for i in range(n):
if d[a[i]] > 0:
if a[i] % k == 0:
x = a[i] // k
if x in d:
d[x] -= 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 ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
from itertools import accumulate
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):
n, k = lst()
a = lst()
a.sort()
s = set()
for v in a:
if v % k != 0 or v // k not in s:
s.add(v)
print(len(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
d = {}
c = 1
p = [0] * n
d[l[0]] = 0
p[0] = 1
for i in range(1, n):
a = c
if l[i] % k == 0 and l[i] // k in d:
a = d[l[i] // k]
c -= 1
d[l[i]] = a
p[a] += 1
c += 1
s = 0
for i in range(n):
if p[i] == 0:
break
s += p[i] // 2
if p[i] % 2 != 0:
s += 1
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 DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split(" "))
a = [int(i) for i in input().split(" ")][:n]
a.sort()
m = dict()
removed = dict()
for i in range(n):
m[a[i]] = int(1)
count = int(n)
for i in range(n):
if removed.get(a[i], 0) == 0:
if m.get(a[i] * k, -1) == 1 and k != 1:
removed[a[i] * k] = 1
count -= 1
print(count)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n = input()
n = n.split(" ")
a, b = int(n[0]), int(n[1])
A = []
S = []
k = b
o = input()
o = o.split(" ")
for i in range(a):
A.append(int(o[i]))
A = sorted(A)
for i in A:
if i % k != 0:
S.append(i)
elif i // k not in S:
S.append(i)
l = len(S)
print(l)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = []
for i in range(n):
if a[i] % k != 0:
ans.append(a[i])
elif a[i] // k not in ans:
ans.append(a[i])
print(len(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 LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
if k == 1:
print(len(nums))
else:
r = set()
for i in sorted(nums):
if i in r:
continue
else:
r.add(i * k)
print(len([i for i in nums if i not in r]))
|
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 IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
s = list(map(int, input().split()))
s = sorted(s)
my_dict = {}
for i in s:
if i not in my_dict:
my_dict[i] = 1
ans = {}
if k != 1:
count = 0
for i in my_dict:
if i * k in my_dict and i not in ans:
ans[i * k] = 1
print(len(my_dict) - len(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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
a = sorted([int(i) for i in input().split()])
b = set(a)
c = list(b)
if k != 1:
for i in c:
if i in b:
b.discard(i * k)
print(len(b))
|
ASSIGN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
h = {}
count = 0
for i in range(n):
h[arr[i]] = 1
for i in range(n):
if h[arr[i]] != 0:
if arr[i] * k in h:
h[arr[i] * k] = 0
count += 1
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 DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
R = lambda: map(int, input().split())
n, k = R()
arr = sorted(list(R()))
s = set(arr)
if k == 1:
print(n)
else:
for x in arr:
if x in s and x * k in s:
s.remove(x * k)
print(len(s))
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
import sys
def main():
n, k = map(int, sys.stdin.readline().strip().split())
arr = list(map(int, sys.stdin.readline().strip().split()))
arr.sort(reverse=True)
dic = {}
for a in arr:
if a * k not in dic:
dic[a] = 1
print(len(dic))
main()
|
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
from sys import stdin
__author__ = "artyom"
def read_next_line():
return list(map(int, stdin.readline().strip().split()))
n, k = read_next_line()
a = read_next_line()
res = set(a)
if k > 1:
excl = set()
for x in reversed(sorted(a)):
if x % k > 0 or x in excl:
continue
p = x / k
if p in res:
res.remove(p)
excl.add(p)
print(len(res))
|
ASSIGN VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
ans = set()
for x in arr:
if x % k == 0:
t = x // k
if t not in ans:
ans.add(x)
else:
ans.add(x)
print(len(ans))
|
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 FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def bs(l=0, r=0, val=0):
l1 = l
r1 = r
while l1 <= r1:
mid = (l1 + r1) // 2
if a[mid] < val:
l1 = mid + 1
elif a[mid] > val:
r1 = mid - 1
elif a[mid] == val:
return mid
return -1
mark = {}
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
for i in range(0, n):
if mark.get(i, False) == False:
temp = bs(i, n - 1, a[i] * k)
mark[temp] = True
sum += 1
print(sum)
|
FUNC_DEF NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR DICT 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 FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def search(v, l, n):
low = 0
hi = n - 1
while low <= hi:
mid = low + (hi - low) // 2
if l[mid] > v:
hi = mid - 1
elif l[mid] < v:
low = mid + 1
else:
return mid
return -1
n, k = map(int, input().strip().split())
v = list(map(int, input().strip().split()))
kmult = [False] * n
if k == 1:
print(n)
quit()
c = n
v.sort()
hi = n
for j in range(n - 1, -1, -1):
i = v[j]
if not kmult[j] and i % k == 0:
pos = search(i // k, v, hi)
if pos >= 0:
kmult[pos] = True
c -= 1
hi = pos
print(c)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
visited = [0] * n
i = 0
group_2 = []
group_1 = []
while i < n:
if visited[i] == 0:
group_1.append(arr[i])
visited[i] = 1
x = arr[i] * k
left = i
right = n - 1
while left <= right:
mid = left + (right - left) // 2
if arr[mid] == x:
visited[mid] = 1
group_2.append(arr[mid])
break
elif arr[mid] < x:
left = mid + 1
else:
right = mid - 1
i += 1
else:
i += 1
print(max(len(group_1), len(group_2)))
|
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 LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
def answer(n, k, A):
A.sort()
d = {}
count = 0
for i in range(n):
if A[i] not in d:
count += 1
d[A[i] * k] = 1
return count
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(answer(n, k, arr))
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER 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 VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
readints = lambda: map(int, input().strip("\n").split())
n, k = readints()
a = list(readints())
a.sort()
ans = set()
for x in a:
if x % k != 0 or x / k not in ans:
ans.add(x)
print(len(ans))
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.
You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^9). The next line contains a list of n distinct positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
All the numbers in the lines are separated by single spaces.
-----Output-----
On the only line of the output print the size of the largest k-multiple free subset of {a_1, a_2, ..., a_{n}}.
-----Examples-----
Input
6 2
2 3 6 5 4 10
Output
3
-----Note-----
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
n, k = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
s = set(a)
l = 0
for x in a:
t = 1
while x in s:
l += t
t = 1 - t
s.remove(x)
x *= k
print(l)
|
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(0, t):
n = int(input())
list1 = [int(num) for num in input().split()]
times = [int(num) for num in input().split()]
list2 = []
for i in range(0, n):
list2.append(list1[i] + times[i])
list2.append(list1[i] - times[i])
list2.sort()
mid = (list2[0] + list2[-1]) / 2
print(mid)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
def segments_intersect(l1, r1, l2, r2):
return l1 <= l2 <= r1 or l1 <= r2 <= r1 or l2 <= l1 <= r2 or l2 <= r1 <= r2
def all_intersect(lhs, rhs):
ext_l = max(lhs)
ext_r = min(rhs)
if ext_l > ext_r:
return False
return all(segments_intersect(ext_l, ext_r, l, r) for l, r in zip(lhs, rhs))
def solve():
n = int(input())
xx = list(map(int, input().split()))
tt = list(map(int, input().split()))
max_t = max(tt)
lhs = [(x - (max_t - t)) for x, t in zip(xx, tt)]
rhs = [(x + (max_t - t)) for x, t in zip(xx, tt)]
if all_intersect(lhs, rhs):
slowest_idx = next(i for i, t in enumerate(tt) if t == max_t)
slowest_x = xx[slowest_idx]
return slowest_x
most_left = min(rhs)
most_right = max(lhs)
return (most_left + most_right) / 2
for test_id in range(int(input())):
print(solve())
|
FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
import sys
input = lambda: sys.stdin.readline().rstrip()
for _ in range(int(input())):
n = int(input())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
print(
(
max(map(lambda x: x[0] + x[1], zip(a, b)))
+ min(map(lambda x: x[0] - x[1], zip(a, b)))
)
/ 2
)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
K = int(input())
while K:
k = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i, j in zip(a, b):
c.append(i - j)
c.append(i + j)
print((max(c) + min(c)) / 2)
K -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [(i + j) for i, j in zip(a, b)]
d = [(i - j) for i, j in zip(a, b)]
print(0.5 * (max(c) + min(d)))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
n = int(input())
for i in range(n):
y = []
x = int(input())
p = input().split(" ")
t = input().split(" ")
for k in range(len(p)):
y.append(int(p[k]) + int(t[k]))
y.append(int(p[k]) - int(t[k]))
y.sort()
print((y[0] + y[-1]) / 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
n = int(input())
for i in range(n):
ppl = input()
positions = list(map(int, input().split()))
gettingready = list(map(int, input().split()))
avg = (max(positions) + min(positions)) / 2
new = []
for i in range(len(positions)):
new.append(positions[i] - gettingready[i])
new.append(positions[i] + gettingready[i])
new_avg = (max(new) + min(new)) / 2
print(new_avg)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
mx = a[0]
mi = a[-1]
for i in range(n):
mx = max(mx, a[i] + b[i])
mi = min(mi, a[i] - b[i])
print(0.5 * (mx + mi))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
def main():
for i in range(int(input())):
test()
def test():
n = int(input())
x = list(map(int, input().split(" ")))
t = list(map(int, input().split(" ")))
mi = x[0] - t[0]
ma = x[0] + t[0]
for i in range(1, n):
mi = min(x[i] - t[i], mi)
ma = max(x[i] + t[i], ma)
print((mi + ma) / 2)
main()
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
cnt = int(input())
while cnt:
n = int(input())
x = list(map(int, input().split()))
t = list(map(int, input().split()))
p, q = min(x), max(x)
for i in range(n):
p = min(p, x[i] - t[i])
q = max(q, x[i] + t[i])
print((p + q) / 2)
cnt -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for i in range(t):
n = int(input())
x = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
l = []
for j in range(n):
l.append(x[j] - p[j])
l.append(x[j] + p[j])
ma = max(l)
mi = min(l)
print((ma + mi) / 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
import sys
sys.setrecursionlimit(1000000)
def mi():
return map(int, input().split())
def li():
return list(mi())
def si():
return str(input())
def ni():
return int(input())
for T in range(int(input())):
n = ni()
x = li()
t = li()
minn = min(x)
maxx = max(x)
for i in range(n):
minn = min(minn, x[i] - t[i])
maxx = max(maxx, x[i] + t[i])
print((minn + maxx) / 2)
|
IMPORT EXPR FUNC_CALL VAR NUMBER 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 FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
arr = input().split(" ")
time = input().split(" ")
arr = [int(i) for i in arr]
time = [int(i) for i in time]
a, b = -(2**31), -(2**31)
for i in range(n):
a = max(a, time[i] + arr[i])
b = max(b, time[i] - arr[i])
if (a - b) % 2:
print((a - b) / 2)
else:
print((a - b) // 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(t):
n = int(input())
pos = [int(i) for i in input().split()]
t_ex = [int(i) for i in input().split()]
pos, t_ex = [
list(x) for x in zip(*sorted(zip(pos, t_ex), key=lambda pair: pair[0]))
]
if n == 1:
print(pos[0])
continue
left = [t_ex[0]]
right = [t_ex[-1]]
for i in range(1, len(pos)):
left.append(max(t_ex[i], left[-1] + pos[i] - pos[i - 1]))
right.append(max(t_ex[-i - 1], right[-1] + pos[-i] - pos[-i - 1]))
right.reverse()
if left[-1] <= right[-1]:
print(pos[-1])
continue
for i in range(len(pos)):
if left[i] >= right[i]:
print(pos[i] + (right[i] - left[i]) / 2.0)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for ncase in range(1, t + 1):
n = int(input())
x = [int(s) for s in input().split(" ")]
t = [int(s) for s in input().split(" ")]
z = [(x[i], x[i] - t[i], x[i] + t[i]) for i in range(n)]
ans = 0
z.sort()
low = z[0][1]
high = z[-1][2]
for i in range(0, n):
if z[i][1] < low:
low = z[i][1]
if z[i][2] > high:
high = z[i][2]
ans = (low + high) / 2
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(t):
n = int(input())
x = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
l = 100000000
r = -100000000
i = 0
while i < n:
if x[i] + t[i] > r:
r = x[i] + t[i]
if x[i] - t[i] < l:
l = x[i] - t[i]
i += 1
print((l + r) / 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
def main():
n_tests = int(input())
for _ in range(n_tests):
n = int(input())
elems = list(map(int, input().split(" ")))
times = list(map(int, input().split(" ")))
updates = []
for i in range(n):
updates.append(elems[i] + times[i])
updates.append(elems[i] - times[i])
min_v, max_v = updates[0], updates[0]
for x in updates:
if x > max_v:
max_v = x
if x < min_v:
min_v = x
print((max_v + min_v) / 2)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
nb_test = int(input())
ans = []
for _ in range(nb_test):
n = int(input())
xs = list(map(int, input().split(" ")))
ts = list(map(int, input().split(" ")))
best = 0
worse_p = 0
worse_n = 0
def dist_p(i):
return xs[i] + ts[i]
def dist_n(i):
return -xs[i] + ts[i]
for i in range(n):
if dist_p(i) >= dist_p(worse_p):
worse_p = i
if dist_n(i) >= dist_n(worse_n):
worse_n = i
an = (xs[worse_p] + xs[worse_n] + ts[worse_p] - ts[worse_n]) / 2
if an.is_integer():
an = int(an)
ans.append(an)
for an in ans:
print(an)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
positions = [int(x) for x in input().split()]
sorted_positions = sorted(positions)
dressing_times = [int(x) for x in input().split()]
max_dressing_time = -1
index_of_maxes = []
for index, time in enumerate(dressing_times):
if time > max_dressing_time:
index_of_maxes = [index]
max_dressing_time = time
elif time == max_dressing_time:
index_of_maxes.append(index)
first_element = sorted_positions[0]
last_element = sorted_positions[-1]
current_min_diff = 200000000.0
centered_max_index = 0
for index in index_of_maxes:
pos = positions[index]
diff = abs(abs(first_element - pos) - abs(last_element - pos))
if diff < current_min_diff:
centered_max_index = index
current_min_diff = diff
centered_pos = positions[centered_max_index]
new_positions = []
for i in range(n):
time = dressing_times[i]
pos = positions[i]
max_time = time + abs(centered_pos - pos)
if max_dressing_time > max_time:
continue
remaining_time = max_dressing_time - time
new_positions.append(
pos - remaining_time if centered_pos < pos else pos + remaining_time
)
sorted_positions = sorted(new_positions)
print((sorted_positions[-1] + sorted_positions[0]) / 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
x = list(map(int, input().split()))
t = list(map(int, input().split()))
mi = x[0] - t[0]
ma = t[0] + x[0]
for i in range(1, n):
l = x[i] - t[i]
h = x[i] + t[i]
if l < mi:
mi = l
if h > ma:
ma = h
print((mi + ma) / 2.0)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
import sys
def main():
t = int(sys.stdin.readline()[:-1])
for _ in range(t):
n = int(sys.stdin.readline()[:-1])
xs = list(map(int, sys.stdin.readline()[:-1].split()))
ts = list(map(int, sys.stdin.readline()[:-1].split()))
ids = list(range(len(xs)))
ids.sort(key=lambda i: xs[i])
_xs, _ts = [], []
for i in ids:
_xs.append(xs[i])
_ts.append(ts[i])
xs, ts = _xs, _ts
d = []
for i in range(len(xs)):
if len(d) == 0:
d.append(ts[i] - xs[i])
else:
d.append(max(d[-1], ts[i] - xs[i]))
s = []
for i in range(len(xs) - 1, -1, -1):
if len(s) == 0:
s.append(ts[i] + xs[i])
else:
s.append(max(s[-1], ts[i] + xs[i]))
s = s[::-1]
_min, pos = float("inf"), -1
for i in range(len(xs)):
cur = max(d[i] + xs[i], s[i] - xs[i])
if cur < _min:
_min, pos = cur, xs[i]
if i > 0:
p = (s[i] - d[i - 1]) / 2
if xs[i - 1] < p < xs[i]:
cur = max(d[i - 1] + p, s[i] - p)
if cur < _min:
_min, pos = cur, p
print(pos)
main()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
output = []
for i in range(t):
n = int(input())
coordinates = [int(c) for c in input().split()]
dress = [int(d) for d in input().split()]
new_coordinates = []
for j in range(n):
if dress[j] != 0:
new_coordinates.append(coordinates[j] - dress[j])
new_coordinates.append(coordinates[j] + dress[j])
n += 1
else:
new_coordinates.append(coordinates[j])
output.append((max(new_coordinates) + min(new_coordinates)) / 2)
for o in output:
print(o)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
from sys import stdin
def main():
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
x = list(map(int, stdin.readline().split()))
times = list(map(int, stdin.readline().split()))
dic = {}
m = -1
m_idx = 0
for i in range(n):
if x[i] in dic:
dic[x[i]] = max(dic[x[i]], times[i])
else:
dic[x[i]] = times[i]
if m < times[i]:
m = times[i]
m_idx = x[i]
min_pos = 1000000000
max_pos = -1
for set in dic.items():
min_pos = min(min_pos, min(m_idx, set[0] + (m - set[1])))
max_pos = max(max_pos, max(m_idx, set[0] - (m - set[1])))
print((min_pos + max_pos) / 2)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
def meeting(arr1, arr2):
k = 0
index = arr1[0]
for i in range(len(arr2)):
if arr2[i] > k:
k = arr2[i]
index = arr1[i]
pos = index
left_side = 0
right_side = 0
for i in range(len(arr1)):
if arr1[i] < pos:
temp1 = pos - arr1[i] + arr2[i]
left_side = max(left_side, temp1)
elif arr1[i] > pos:
temp2 = arr1[i] - pos + arr2[i]
right_side = max(right_side, temp2)
if left_side >= k and right_side >= k:
opt_pos = index + (right_side - left_side) / 2
elif left_side <= k and right_side <= k:
opt_pos = index
elif left_side <= k and right_side >= k:
opt_pos = index + (right_side - k) / 2
else:
opt_pos = index - (left_side - k) / 2
if opt_pos < 0:
return 0
else:
return opt_pos
k = int(input())
for i in range(k):
n = int(input())
arr1 = input().split()
arr1 = [int(l) for l in arr1]
arr2 = input().split()
arr2 = [int(l) for l in arr2]
print(meeting(arr1, arr2))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
def solve():
n = int(input())
lst = list(map(int, input().split()))
t = list(map(int, input().split()))
arr = []
for i in range(n):
arr += [lst[i] - t[i], lst[i] + t[i]]
s = max(arr) + min(arr)
if s % 2 == 0:
print(s // 2)
else:
print(s // 2, end="")
print(".", end="")
print(5)
while t:
solve()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
test = int(input())
for _ in range(test):
input()
l = 10000000000.0
r = -10000000000.0
index = [int(x) for x in input().split()]
time = [int(x) for x in input().split()]
for i, j in zip(index, time):
l = min(l, i - j)
r = max(r, i + j)
print((l + r) / 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
def solve():
n = int(input())
x = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
tmax = max(t)
xlower = 10**9
xupper = -1
for i in range(n):
if t[i] == tmax:
if x[i] < xlower:
xlower = x[i]
if x[i] > xupper:
xupper = x[i]
mp = (xlower + xupper) / 2
time_mp = tmax + (xupper - xlower) / 2
leftmost = mp
rightmost = mp
for i in range(n):
if x[i] < mp:
rnge = time_mp - t[i]
if x[i] + rnge < leftmost:
leftmost = x[i] + rnge
elif x[i] > mp:
rnge = time_mp - t[i]
if x[i] - rnge > rightmost:
rightmost = x[i] - rnge
print((leftmost + rightmost) / 2)
for _ in range(t):
solve()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
x = list(map(int, input().split()))
t = list(map(int, input().split()))
arr = []
for i in range(n):
arr.append(x[i] - t[i])
arr.append(x[i] + t[i])
ans = (max(arr) + min(arr)) / 2
if int(ans) == ans:
print(int(ans))
else:
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
def N():
return int(input())
def A():
return [int(x) for x in input().split()]
def S():
return input()
for _ in range(N()):
a = []
b = []
n = N()
x = A()
if "dutrhg39fer89" == 32474864432759553:
print("Tanmay")
t = A()
m = max(t)
for i in range(n):
dif = m - t[i]
b.append(dif + x[i])
a.append(max(0, x[i]) - dif)
maxi = min(b)
mini = max(a)
print(int(maxi + mini) / 2)
|
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
R = lambda: map(int, input().split())
(t,) = R()
exec(t * "R();a=*zip(R(),R()),;print((max(x+y for x,y in a)+min(x-y for x,y in a))/2);")
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
while t > 0:
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
left = a[0]
right = a[-1]
for i in range(n):
if a[i] - b[i] < left:
left = a[i] - b[i]
if a[i] + b[i] > right:
right = a[i] + b[i]
ans = (left + right) / 2
print(ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for i in range(int(input())):
n = int(input())
nums = list(map(int, input().split()))
tim = list(map(int, input().split()))
cal = sorted(list(zip(tim, nums)), reverse=True)
ans = [cal[0][0], cal[0][1]]
for i in cal:
if ans[1] < i[1]:
if i[1] - ans[1] + i[0] > ans[0]:
v = (i[1] - ans[1] + i[0] - ans[0]) / 2
ans[0], ans[1] = ans[0] + v, ans[1] + v
elif ans[1] > i[1]:
if -i[1] + ans[1] + i[0] > ans[0]:
v = (-i[1] + ans[1] + i[0] - ans[0]) / 2
ans[0], ans[1] = ans[0] + v, ans[1] - v
print(ans[1])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
import sys
from itertools import accumulate
input = sys.stdin.readline
def find_max(t):
m = 0
ind = 0
for i, val in enumerate(t):
if val > m:
m = val
ind = i
return ind, m
for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
t = list(map(int, input().split()))
ind, m = find_max(t)
pi = p[ind]
ls = [
(max(p[k] - (m - t[k]), pi) if p[k] >= pi else min(p[k] + (m - t[k]), pi))
for k in range(n)
]
print((max(ls) + min(ls)) / 2)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
a = int(input())
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [(c[i] + b[i]) for i in range(a)]
e = [(b[i] - c[i]) for i in range(a)]
d.extend(e)
mi, ma = min(d), max(d)
if (mi + ma) % 2 == 0:
print((mi + ma) // 2)
else:
print((mi + ma) / 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _, (xs, ts) in (
(input(), (tuple(map(int, input().split())) for _ in "00"))
for _ in range(int(input()))
):
print((max(x + t for x, t in zip(xs, ts)) + min(x - t for x, t in zip(xs, ts))) / 2)
|
FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(t):
n = int(input())
x = list(map(int, input().split(" ")))
t = list(map(int, input().split(" ")))
r = [(a + b) for a, b in zip(x, t)]
l = [(a - b) for a, b in zip(x, t)]
o = (max(r) + min(l)) / 2
print(int(o) if o % 1 == 0 else o)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
s = int(input())
while s != 0:
n = int(input())
x = list(map(int, input().split()))
t = list(map(int, input().split()))
mx = x[0] + t[0]
mi = x[0] - t[0]
for i in range(1, n):
mi = min(mi, x[i] - t[i])
mx = max(mx, x[i] + t[i])
sum = mi + mx
if sum % 2 == 0:
print(sum // 2)
else:
print(str(sum // 2) + ".5")
s -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
ntestcases = int(input())
for t in range(ntestcases):
numPeople = int(input())
positions = list(map(int, input().split(" ")))
dressingTimes = list(map(int, input().split(" ")))
if dressingTimes[0] > 0:
minPos = positions[0] - dressingTimes[0]
maxPos = positions[0] + dressingTimes[0]
else:
minPos = positions[0]
maxPos = positions[0]
for i in range(1, numPeople):
if dressingTimes[i] > 0:
smol = positions[i] - dressingTimes[i]
big = positions[i] + dressingTimes[i]
minPos = min(minPos, smol)
maxPos = max(maxPos, big)
else:
minPos = min(minPos, positions[i])
maxPos = max(maxPos, positions[i])
answer = (maxPos + minPos) / 2
intAnswer = int(answer)
if answer == intAnswer:
print(intAnswer)
else:
print(answer)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(t):
n = int(input())
x = list(map(int, input().split()))
time = list(map(int, input().split()))
if len(x) == 1:
print(x[0])
continue
st = sorted(list(zip(x, time)), key=lambda p: p[1])
max_time = st[-1]
time = list(map(lambda p: p - max_time[1], time))
st = sorted(list(zip(x, time)), key=lambda p: p[0])
most_left = None
most_right = None
for obj in st:
left = obj[0] + obj[1]
right = obj[0] - obj[1]
mid = obj[0]
if left <= max_time[0] <= right:
if most_left is None:
most_left = max_time[0]
most_left = min(most_left, max_time[0])
if most_right is None:
most_right = max_time[0]
most_right = max(most_right, max_time[0])
else:
if mid < max_time[0]:
if most_left is None:
most_left = right
most_left = min(most_left, right)
if mid > max_time[0]:
if most_right is None:
most_right = left
most_right = max(most_right, left)
print((most_left + most_right) / 2.0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR IF VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(t):
n = int(input())
x_str = input()
time_str = input()
list_of_x_str = x_str.split(" ")
x = [int(a) for a in list_of_x_str]
list_of_time_str = time_str.split(" ")
time = [int(a) for a in list_of_time_str]
count = 0
min_cor = 200000000
max_cor = 0
for i in range(n):
count += 1
min_cor = min(min_cor, x[i] - time[i])
max_cor = max(max_cor, x[i] + time[i])
print((min_cor + max_cor) / 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
for _ in range(t):
n = int(input())
list_time, list_cord = [], []
list_cord = list(map(int, input().split()))
list_time = list(map(int, input().split()))
list_all_x_points = [(0) for i in range(2 * n)]
for i in range(0, 2 * n, 2):
list_all_x_points[i] = list_cord[i // 2] + list_time[i // 2]
list_all_x_points[1 + i] = list_cord[i // 2] - list_time[i // 2]
maxi = mini = list_all_x_points[0]
for i in list_all_x_points:
maxi = max(maxi, i)
mini = min(mini, i)
sum = mini + maxi
print(sum // 2, end="")
if sum % 2:
print(".5")
else:
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
import sys
t = int(sys.stdin.readline())
for i in range(t):
n = int(input())
lstx = list(map(int, input().split()))
lsty = list(map(int, input().split()))
low = min(lstx)
high = max(lstx)
l = 0
r = 200000001
mid = (l + r) / 2
ans = r
while True:
if r < l:
break
mid = (l + r) // 2
lt = -1000000000000000.0
rt = 1000000000000000.0
er = 0
for j in range(n):
left = mid - lsty[j]
if left < 0:
er += 1
break
a = lstx[j] - left
b = lstx[j] + left
if a > r or b < l:
er += 1
break
lt = max(lt, a)
rt = min(rt, b)
if er > 0:
l = mid + 1
else:
ans = (lt + rt) / 2
r = mid - 1
if int(ans) == ans:
ans = int(ans)
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
t = int(input())
while t > 0:
n = int(input())
x = list(map(int, input().split(" ")))
time = list(map(int, input().split(" ")))
a = list()
for i in range(n):
a.append(x[i] + time[i])
a.append(x[i] - time[i])
minn = a[0]
maxx = a[0]
for v in a:
minn = min(minn, v)
maxx = max(maxx, v)
summ = maxx + minn
print(summ / 2)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
for _ in range(int(input())):
n = int(input())
x = list(map(int, input().split()))
t = list(map(int, input().split()))
if t.count(0) == len(t):
print((max(x) + min(x)) / 2)
else:
a = []
for i in range(n):
a.append(x[i] - t[i])
a.append(x[i] + t[i])
print((max(a) + min(a)) / 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
|
$n$ people live on the coordinate line, the $i$-th one lives at the point $x_i$ ($1 \le i \le n$). They want to choose a position $x_0$ to meet. The $i$-th person will spend $|x_i - x_0|$ minutes to get to the meeting place. Also, the $i$-th person needs $t_i$ minutes to get dressed, so in total he or she needs $t_i + |x_i - x_0|$ minutes.
Here $|y|$ denotes the absolute value of $y$.
These people ask you to find a position $x_0$ that minimizes the time in which all $n$ people can gather at the meeting place.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. Then the test cases follow.
Each test case consists of three lines.
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of people.
The second line contains $n$ integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^{8}$) — the positions of the people.
The third line contains $n$ integers $t_1, t_2, \dots, t_n$ ($0 \le t_i \le 10^{8}$), where $t_i$ is the time $i$-th person needs to get dressed.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print a single real number — the optimum position $x_0$. It can be shown that the optimal position $x_0$ is unique.
Your answer will be considered correct if its absolute or relative error does not exceed $10^{−6}$. Formally, let your answer be $a$, the jury's answer be $b$. Your answer will be considered correct if $\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$.
-----Examples-----
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
-----Note-----
In the $1$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $3$ minutes, that he or she need to get dressed.
In the $2$-nd test case there are $2$ people who don't need time to get dressed. Each of them needs one minute to get to position $2$.
In the $5$-th test case the $1$-st person needs $4$ minutes to get to position $1$ ($4$ minutes to get dressed and $0$ minutes on the way); the $2$-nd person needs $2$ minutes to get to position $1$ ($1$ minute to get dressed and $1$ minute on the way); the $3$-rd person needs $4$ minutes to get to position $1$ ($2$ minutes to get dressed and $2$ minutes on the way).
|
n = int(input())
z = []
for i in range(n):
y = []
x = int(input())
p = input().split(" ")
t = input().split(" ")
for k in range(len(p)):
y.append(int(p[k]) + int(t[k]))
y.append(int(p[k]) - int(t[k]))
min = 1000000000
max = 0
for i in range(len(y)):
if y[i] > max:
max = y[i]
elif y[i] < min:
min = y[i]
print((max + min) / 2)
for a in range(len(z)):
print(z[a])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.
The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).
Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of hashtags being edited now.
Each of the next n lines contains exactly one hashtag of positive length.
It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.
-----Output-----
Print the resulting hashtags in any of the optimal solutions.
-----Examples-----
Input
3
#book
#bigtown
#big
Output
#b
#big
#big
Input
3
#book
#cool
#cold
Output
#book
#co
#cold
Input
4
#car
#cart
#art
#at
Output
#
#
#art
#at
Input
3
#apple
#apple
#fruit
Output
#apple
#apple
#fruit
-----Note-----
Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold: at first position i, such that a_{i} ≠ b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ; if there is no such position i and m ≤ k, i.e. the first word is a prefix of the second or two words are equal.
The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.
For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.
According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.
|
n = int(input())
hashtags = []
for i in range(n):
hashtags.append(input())
for i in range(n - 2, -1, -1):
if hashtags[i] > hashtags[i + 1]:
pointer = 0
while (
pointer < len(hashtags[i + 1])
and hashtags[i][pointer] == hashtags[i + 1][pointer]
):
pointer += 1
hashtags[i] = hashtags[i][:pointer]
print("\n".join(hashtags))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.