description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | for _ in range(int(input())):
n = int(input())
d = {}
deg = {}
weight = []
for i in range(n - 1):
u, v, w = map(int, input().split())
weight.append(w)
if d.get(u) == None:
d[u] = [v]
deg[u] = 1
else:
d[u].append(v)
deg[u] += 1
if d.get(v) == None:
d[v] = [u]
deg[v] = 1
else:
d[v].append(u)
deg[v] += 1
node = list(map(int, input().split()))
node.sort(reverse=True)
weight.sort(reverse=True)
weight.insert(1, weight[0])
count = 0
j = 0
for i in range(n):
if weight[i] > node[j]:
count += 1
else:
j += 1
print(count) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR LIST VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | import sys
T = int(input())
for t in range(T):
N = int(input())
B = [0] * (N - 1)
for i in range(N - 1):
ui, vi, b = map(int, sys.stdin.readline().split(" "))
B[i] = b
A = list(map(int, sys.stdin.readline().split(" ")))
A.sort(reverse=True)
B.sort(reverse=True)
count = 0
i = 0
j = 0
if A[0] < B[0]:
count += 1
else:
j = 1
while i < N - 1:
if B[i] > A[j]:
count += 1
else:
j += 1
i += 1
print(count) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | T = int(input())
for v in range(T):
n = int(input(""))
g = []
b = []
for i in range(n + 1):
g.append([])
for i in range(n - 1):
a = input("").split(" ")
u = int(a[0])
v = int(a[1])
g[u].append(v)
g[v].append(u)
e = int(a[2])
b.append(e)
a = list(map(int, input("").split(" ")))
b.sort()
a.sort()
i = 0
j = 0
pos = []
c = 0
while i < n and j < n - 1:
if b[j] <= a[i]:
c = c + 1
j = j + 1
else:
pos.append(c)
i = i + 1
if j == n - 1:
while i < n:
pos.append(c)
i = i + 1
num = [0]
for i in range(1, n + 1, 1):
num.append(len(g[i]))
mn = n
cur = 0
for i in range(1, n + 1, 1):
if num[i] < mn:
mn = num[i]
cur = i
t = 0
I = 0
ed = 0
mn = 1
while I < n - 1:
p = pos[I]
if p - ed >= mn:
ed = ed + mn
else:
t = t + 1
I = I + 1
if ed == n - 1:
print(0)
elif ed < n - 1:
if pos[-1] - ed >= mn:
print(t)
else:
print(t + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | maxi = None
ans = 0
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
self.v = 1
def insertNode(root, data, par):
if root is None:
if data <= par.data:
par.left = Node(data)
else:
par.right = Node(data)
return
if data <= root.data:
insertNode(root.left, data, root)
else:
insertNode(root.right, data, root)
def findJustMax(data, root):
global maxi
if root is None:
return
if data >= root.data and root.v == 1:
if maxi is None or root.data > maxi.data:
maxi = root
findJustMax(data, root.right)
else:
findJustMax(data, root.left)
def giveAns(root):
global ans
if root is None:
return
if root.v == 1:
ans += 1
giveAns(root.left)
giveAns(root.right)
for h in range(int(input())):
N = int(input())
w = []
for _ in range(N - 1):
w.append(int(input().strip().split()[2]))
a = list(map(int, input().strip().split()))
req = [max(w)] + w
req.sort()
a.sort()
c = 0
j = 0
for i in a:
if i >= req[j]:
j += 1
else:
c += 1
print(c) | ASSIGN VAR NONE ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NONE RETURN IF VAR VAR VAR NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NONE RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | for _ in range(int(input())):
n = int(input())
if n < 200:
deg = [0] * n
graph = [[] for i in range(n + 1)]
edg = []
for i in range(n - 1):
a, b, c = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
deg[a - 1] += 1
deg[b - 1] += 1
edg.append(c)
ve = list(map(int, input().split()))
ve.sort()
edg.sort()
ep = 0
vp = 0
ans = 0
while True:
di = min(deg)
if di == 0 or di > 10**9:
break
fl = 0
while fl == 0:
k = ep
for i in range(di):
if edg[k] > ve[vp]:
fl = 0
break
k += 1
fl = 1
if fl == 0:
vp += 1
ve.append(10**9 + 1)
ans += 1
else:
ep = k
vp += 1
x = deg.index(di)
deg[x] = 10**9 + 1
for i in graph[x + 1]:
deg[i - 1] -= 1
print(ans)
else:
deg = [0] * n
graph = [[] for i in range(n + 1)]
edg = []
for i in range(n - 1):
a, b, c = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
deg[a - 1] += 1
deg[b - 1] += 1
edg.append(c)
ve = list(map(int, input().split()))
ve.sort()
edg.sort()
op = set()
for i in range(n):
if deg[i] == 1:
op.add(i)
ep = 0
vp = 0
ans = 0
while True:
if ep == n - 2:
break
if len(op) == 1:
break
di = 1
if di == 0 or di > 10**9:
break
fl = 0
while fl == 0:
k = ep
for i in range(di):
if edg[k] > ve[vp]:
fl = 0
break
k += 1
fl = 1
if fl == 0:
vp += 1
ve.append(10**9 + 1)
ans += 1
else:
ep = k
vp += 1
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | from sys import stdin, stdout
try:
testcase = stdin.readline()
for __ in range(0, int(testcase)):
m = stdin.readline()
m = int(m)
b = []
for i in range(0, m - 1):
b1 = [int(_) for _ in stdin.readline().split()]
b.append(b1[2])
b = sorted(b)
a = [int(_) for _ in stdin.readline().split()]
a = sorted(a)
ans, j = 0, 0
for i in a:
if i >= b[j]:
j += 1
else:
ans += 1
if j == m - 1:
break
print(ans)
except:
pass | ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | T = int(input())
for _ in range(T):
N = int(input())
eWeights = []
for i in range(N - 1):
eWeights.append([int(x) for x in input().strip().split()])
nWeights = [int(x) for x in input().strip().split()]
n = len(nWeights)
edgeWeights = []
nodeWeights = []
for u, v, w in eWeights:
edgeWeights.append(w)
INF = 10**10
nodeWeights = nWeights
edgeWeights.sort()
nodeWeights.sort()
count = 0
i = 0
j = 0
if n > 1000:
while True:
if i == len(edgeWeights) - 1:
break
if i == len(edgeWeights) - 1:
if nodeWeights[j] >= edgeWeights[i]:
if nodeWeights[j + 1] >= edgeWeights[i]:
break
if nodeWeights[j + 1] < edgeWeights[i]:
count += 2
break
if nodeWeights[j] >= edgeWeights[i]:
j += 1
i += 1
else:
j += 1
nodeWeights.append(10**10)
count += 1
else:
while True:
if len(edgeWeights) == 0:
break
if len(edgeWeights) == 1:
if nodeWeights[0] >= edgeWeights[0] or nodeWeights[0] == INF:
if nodeWeights[1] >= edgeWeights[0] or nodeWeights[1] == INF:
break
if nodeWeights[1] < edgeWeights[0] and nodeWeights[1] != INF:
count += 2
break
if nodeWeights[0] >= edgeWeights[0] or nodeWeights[0] == INF:
edgeWeights = edgeWeights[1:]
nodeWeights = nodeWeights[1:]
else:
nodeWeights = nodeWeights[1:]
nodeWeights.append(INF)
count += 1
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | def printMinCoins(edges, vertices):
edges.sort(reverse=True)
vertices.sort(reverse=True)
edgeCount = len(edges)
minCoins = 0
i = 0
if vertices[i] >= edges[0]:
i += 1
else:
minCoins += 1
for j in range(len(edges)):
if vertices[i] >= edges[j]:
i += 1
else:
minCoins += 1
print(minCoins)
T = int(input())
while T > 0:
T -= 1
N = int(input())
edges = []
for i in range(N - 1):
x = list(map(int, input().split()))
edges.append(x[2])
vertices = list(map(int, input().split()))
printMinCoins(edges, vertices) | FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | def testcase():
n = int(input())
node = set()
weight = []
maximumWeight = 0
for i in range(n - 1):
u, v, w = [int(_) for _ in input().split()]
weight.append(w)
maximumWeight = max(maximumWeight, w)
weight.append(maximumWeight)
weight.sort(reverse=True)
node = [int(i) for i in input().split()]
node.sort(reverse=True)
j = 0
counter = 0
for i in weight:
if i > node[j]:
counter += 1
else:
j += 1
print(counter)
t = int(input())
for test in range(t):
testcase() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | T = int(input())
for time in range(T):
N = int(input())
A = []
B = []
res = 0
a1 = 0
b1 = 0
for itr in range(N - 1):
u, v, b = map(int, input().split())
B.append(b)
A = list(map(int, input().split()))
A.sort()
B.sort()
while a1 < N and b1 < N - 1:
if A[a1] >= B[b1]:
a1 += 1
b1 += 1
else:
a1 += 1
res += 1
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | for i in range(int(input())):
n = int(input())
e = []
for i in range(n - 1):
l = list(map(int, input().split()))
e.append(l[2])
v = list(map(int, input().split()))
e = sorted(e)
v = sorted(v)
p = e[-1]
q = v[-1]
if p > q:
ans = 2
e.pop()
v.pop(0)
v.pop(0)
elif p > v[-2]:
ans = 1
e.pop()
v.pop(0)
v.pop()
else:
ans = 0
e.pop()
v.pop()
v.pop()
a = n - 2
while a > 0:
a -= 1
if e[-1] <= v[-1]:
e.pop()
v.pop()
else:
ans += 1
e.pop()
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a tree with $N$ vertices (numbered $1$ through $N$). Its edges are numbered $1$ through $N-1$. For each valid $i$, there is an integer $a_{i}$ written on the $i$-th vertex. Also, for each valid $i$, there is an integer $b_{i}$ written on the $i$-th edge.
You want the following condition to be satisfied: for each vertex $v$ and each edge $e$ adjacent to $v$, $a_{v} β₯ b_{e}$. In order to achieve that, you may perform an arbitrary number of steps (including zero). In one step, you may perform one the following operations:
1. Select two different vertices $u$ and $v$. Swap $a_{u}$ and $a_{v}$.
2. Select two different edges $e$ and $f$. Swap $b_{e}$ and $b_{f}$.
3. Select a vertex $v$ and an integer $x$. Change $a_{v}$ to $x$ and pay one coin.
Calculate the minimum number of coins you need in order to satisfy the required condition.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N-1$ lines follow. For each $i$ ($1 β€ i β€ N-1$), the $i$-th of these lines contains three space-separated integers $u_{i}$, $v_{i}$ and $b_{i}$ denoting that the $i$-th edge connects vertices $u_{i}$ and $v_{i}$ and the initial value written on it is $b_{i}$.
The last line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the minimum necessary number of coins.
------ Constraints ------
$1 β€ T β€ 10$
$2 β€ N β€ 100,000$
$1 β€ u_{i}, v_{i} β€ N$ for each valid $i$
$1 β€ b_{i} β€ 10^{9}$ for each valid $i$
$1 β€ a_{i} β€ 10^{9}$ for each valid $i$
the graph on the input is a tree
------ Subtasks ------
Subtask #1 (10 points): $N β€ 7$
Subtask #2 (10 points): $N β€ 10$
Subtask #3 (30 points): $N β€ 200$
Subtask #4 (50 points): original constraints
----- Sample Input 1 ------
1
3
1 2 4
2 3 7
1 5 10
----- Sample Output 1 ------
1
----- explanation 1 ------
Example case 1: There is no way to satisfy the required condition without paying any coins. When we have one coin, we can perform the following operations:
- Swap the integers written on vertices $1$ and $2$.
- Pay one coin and change the integer written on vertex $2$ to $7$. | for _ in range(int(input())):
n = int(input())
arr_real = []
for _ in range(n - 1):
a, b, val = map(int, input().split())
arr_real.append(val)
arr_given = list(map(int, input().split()))
arr_real.sort(reverse=True)
arr_real = [arr_real[0]] + arr_real
arr_given.sort(reverse=True)
i, j = 0, 0
while i != n:
if arr_given[j] >= arr_real[i]:
i += 1
j += 1
else:
i += 1
print(n - j) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
ans = [(0) for i in range(n)]
for i in range(n):
if a[i] not in d:
d[a[i]] = [b[i]]
else:
d[a[i]].append(b[i])
for i in d:
k = len(d[i])
d[i] = sorted(d[i], reverse=True)
for j in range(1, k):
d[i][j] += d[i][j - 1]
for j in range(1, n + 1):
m = k // j
if m != 0:
ans[j - 1] += d[i][m * j - 1]
else:
break
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 DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for i in range(int(input())):
n = int(input())
uni = list(map(int, input().split()))
skills = list(map(int, input().split()))
d = {}
for i in range(n):
if uni[i] in d:
d[uni[i]].append(skills[i])
else:
d[uni[i]] = [skills[i]]
ans = [0] * n
for i in d:
d[i].sort(reverse=True)
m = len(d[i])
for j in range(1, m):
d[i][j] += d[i][j - 1]
for j in range(m):
v = 1 + j
mod = m % v
ans[j] += d[i][-(mod + 1)]
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for i in range(t):
n = int(input())
u = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
d = [[] for i in range(n)]
ln = [0] * n
for i in range(n):
d[u[i] - 1].append(s[i])
ln[u[i] - 1] += 1
for i in range(n):
if not d[i]:
continue
d[i].sort(reverse=True)
for j in range(1, ln[i]):
d[i][j] += d[i][j - 1]
d[i] = [0] + d[i]
ans = [0] * n
for i in range(n):
if not d[i]:
continue
for j in range(ln[i]):
ans[j] += d[i][ln[i] - ln[i] % (j + 1)]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for test in range(t):
n = int(input())
uni = list(map(int, input().split()))
skill = list(map(int, input().split()))
total = sum(skill)
teams = {}
for i in range(n):
if uni[i] - 1 not in teams:
teams[uni[i] - 1] = []
teams[uni[i] - 1].append(skill[i])
partial_sums = {}
for k, t in teams.items():
t.sort()
partial_sums[k] = [0]
run_sum = 0
for num in t:
run_sum += num
partial_sums[k].append(run_sum)
ans = [0] * n
for k, t in teams.items():
for x in range(len(t)):
ans[x] += partial_sums[k][-1] - partial_sums[k][len(t) % (x + 1)]
for x in ans:
print(x, end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER LIST EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def rt(n, r, m):
dp = [[] for i in range(0, m)]
for i in range(0, len(n)):
dp[n[i] - 1].append(r[i])
q = []
p1 = [[(0) for i in range(0, len(dp[k]))] for k in range(0, m)]
for i in range(0, len(dp)):
dp[i].sort(reverse=True)
for x in range(0, len(dp[i])):
if x == 0:
p1[i][x] = dp[i][x]
else:
p1[i][x] = p1[i][x - 1] + dp[i][x]
if len(dp[i]) >= 1:
q.append([len(dp[i]), i])
s = 0
q.sort()
l1 = 1
r1 = [(0) for i in range(0, m)]
while s < len(q):
c1 = 0
for k in range(s, len(q)):
[a, b] = q[k]
if a >= l1:
z1 = a - a % l1 - 1
c1 = c1 + p1[b][z1]
else:
s = s + 1
if l1 - 1 < m:
r1[l1 - 1] = c1
l1 = l1 + 1
return r1
s = int(input())
for i in range(0, s):
s1 = int(input())
n = list(map(int, input().split()))
r = list(map(int, input().split()))
x = rt(n, r, s1)
for j in x:
print(j, end=" ")
print("") | FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
while t != 0:
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
net = dict()
for i in range(n):
if u[i] in net:
net[u[i]].append(s[i])
else:
net[u[i]] = [s[i]]
for i in net:
x = net[i]
x.sort()
k = len(x)
l = [0] * k
l[0] = x[0]
for j in range(1, k):
l[j] = l[j - 1] + x[j]
net[i] = l
ans = [0] * n
for i in net:
x = net[i]
for k in range(1, len(x) + 1):
s = 0
left = len(x) % k
if left != 0:
s = x[-1] - x[left - 1]
else:
s = x[-1]
ans[k - 1] += s
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 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
us = [[] for j in range(n)]
for i in range(n):
us[u[i] - 1].append(s[i])
s = [0] * n
for i in range(n):
if us[i] == []:
continue
us[i].sort()
p = len(us[i])
if p > 1:
for j in range(p - 2, -1, -1):
us[i][j] += us[i][j + 1]
for j in range(1, p + 1):
k = p % j
s[j - 1] += us[i][k]
print(*s) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for t in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
store = {}
for i in range(n):
if a[i] not in store:
store[a[i]] = []
store[a[i]].append(b[i])
ans = [(0) for i in range(n + 1)]
for i in store:
store[i] = sorted(store[i])[::-1]
s = 0
a = [0]
for j in store[i]:
s += j
a.append(s)
l = len(a) - 1
for j in range(1, l + 1):
x = j * (l // j)
ans[j] += a[x]
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def solve():
u = list(map(int, input().split()))
s = list(map(int, input().split()))
u = [x for x in sorted(zip(s, u))]
uni = [[0] for _ in range(n)]
for i in reversed(u):
uni[i[1] - 1].append(uni[i[1] - 1][-1] + i[0])
ans = [0] * n
for i in uni:
x = len(i) - 1
for j in range(1, x + 1):
ans[j - 1] += i[x - x % j]
return " ".join(str(x) for x in ans)
for t in range(int(input())):
n = int(input())
print(solve()) | FUNC_DEF 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
univ = list(map(int, input().split()))
skill = list(map(int, input().split()))
each = [[] for i in range(n + 1)]
for i in range(n):
each[univ[i]].append(skill[i])
for i in range(n + 1):
each[i].sort(reverse=True)
add = 0
ll = len(each[i])
for j in range(ll):
add += each[i][j]
each[i][j] = add
ans = [0] * (n + 1)
for i in range(1, n + 1):
ll = len(each[i])
for j in range(1, ll + 1):
ans[j] += each[i][ll // j * j - 1]
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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
un = list(map(int, input().split()))
sk = list(map(int, input().split()))
p = max(un)
l = [[] for i in range(p)]
for i in range(n):
l[un[i] - 1].append(sk[i])
l.sort(key=len, reverse=True)
for i in range(p):
l[i].sort(reverse=True)
for j in range(1, len(l[i])):
l[i][j] += l[i][j - 1]
ans = [(0) for i in range(n)]
for i in range(1, n + 1):
sumo = 0
for j in range(p):
x = len(l[j])
if i <= x:
sumo += l[j][x - 1 - x % i]
else:
break
ans[i - 1] = sumo
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 FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
un = [[] for _ in range(n)]
for i in range(n):
un[u[i] - 1].append(s[i])
for i in range(n):
un[i].sort(reverse=True)
ans = [(0) for _ in range(n)]
for u in range(n):
l = len(un[u])
p = [(0) for _ in range(l + 1)]
for i in range(l):
p[i + 1] = un[u][i] + p[i]
for k in range(1, l + 1):
ans[k - 1] += p[l // k * k]
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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = [0] * n
d = [[0] for i in range(n)]
for i, j in zip(map(int, input().split()), map(int, input().split())):
d[i - 1].append(j)
for i in range(n):
d[i].sort()
for j in range(1, len(d[i])):
d[i][j] += d[i][j - 1]
for j in range(1, len(d[i])):
a[j - 1] += d[i][-1] - d[i][(len(d[i]) - 1) % j]
print(" ".join(map(str, a))) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for inh in range(0, t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
a = {}
uni = set()
for i in range(0, n):
if u[i] in uni:
a[u[i]].append(s[i])
else:
a[u[i]] = [s[i]]
uni.add(u[i])
uni = list(uni)
ans = [0] * n
for i in range(0, len(uni)):
k = a[uni[i]]
k.sort(reverse=True)
i, j = 1, len(k)
while i < len(k):
k[i] += k[i - 1]
i += 1
for i in range(1, j + 1):
last = j - j % i - 1
ans[i - 1] += k[last]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import itertools
import sys
def rl():
return sys.stdin.readline().strip()
def rl_types(types):
str_list = [x for x in sys.stdin.readline().strip().split(" ")]
return [types[i](str_list[i]) for i in range(len(str_list))]
def pr(something):
sys.stdout.write(str(something) + "\n")
def pra(array):
sys.stdout.write(" ".join([str(x) for x in array]) + "\n")
def solve(univs, studs, n):
by_univ = {i: [] for i in range(1, n + 1)}
for i in range(n):
by_univ[univs[i]].append(studs[i])
all_studs = {}
l = {}
for sch in range(1, n + 1):
students = sorted(by_univ[sch], reverse=True)
l = len(students)
if not l in all_studs:
all_studs[l] = [0] * l
temp = all_studs[l]
for i in range(l):
temp[i] += students[i]
all_studs[l] = temp
if 0 in all_studs:
del all_studs[0]
for l in all_studs:
all_studs[l] = [x for x in itertools.accumulate(all_studs[l])]
k_vals = [0] * n
for k in range(1, n + 1):
for l in all_studs:
if k > l:
continue
ig = l % k
k_vals[k - 1] += all_studs[l][l - ig - 1]
return k_vals
NT = int(rl())
for ti in range(NT):
n = int(rl())
univs = [int(x) for x in rl().split(" ")]
studs = [int(x) for x in rl().split(" ")]
res = solve(univs, studs, n)
pra(res) | IMPORT IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING FUNC_DEF ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
t = int(input())
result = []
for _ in range(t):
n = int(input())
arrayOne = list(map(int, input().split()))
arrayTwo = list(map(int, input().split()))
def solve():
hashMap = {num: [] for num in arrayOne}
for numOne, numTwo in zip(arrayOne, arrayTwo):
hashMap[numOne].append(numTwo)
for num in hashMap:
hashMap[num].sort(reverse=True)
prefixSum = {num: [] for num in arrayOne}
res = [(0) for i in range(n)]
for num in hashMap:
currentSum = 0
for numOne in hashMap[num]:
currentSum += numOne
prefixSum[num].append(currentSum)
for num in hashMap:
for k in range(1, len(hashMap[num]) + 1):
remainder = len(hashMap[num]) % k
res[k - 1] += prefixSum[num][len(hashMap[num]) - remainder - 1]
return res
res = solve()
print(" ".join([str(num) for num in res])) | IMPORT 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR LIST VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
x = dict()
ans = [0] * n
for i in range(n):
try:
x[u[i]].append(s[i])
except:
x[u[i]] = [s[i]]
for i in x.keys():
x[i].sort(reverse=True)
sv = dict()
for j in range(0, len(x[i])):
try:
sv[i].append(sv[i][j - 1] + x[i][j])
except:
sv[i] = [x[i][0]]
for j in range(1, len(x[i]) + 1):
rem = len(x[i]) % j
ans[j - 1] += sv[i][-1 - rem]
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
c = []
st = set()
for i in range(n):
c.append([s[i], u[i]])
st.add(u[i])
u = []
s = []
c.sort(reverse=True, key=lambda p: p[0])
a = []
for i in range(n + 1):
a.append([0])
for i in range(n):
a[c[i][1]].append(c[i][0] + a[c[i][1]][-1])
c = []
sm = []
for k in range(1, n + 1):
cnt = 0
rem = []
for j in st:
if k > len(a[j]) - 1:
rem.append(j)
continue
cnt += a[j][len(a[j]) - 1 - (len(a[j]) - 1) % k]
for j in rem:
st.remove(j)
sm.append(cnt)
print(*sm) | IMPORT ASSIGN 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 LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def mapit():
temp = list(map(int, input().split()))
return temp
def solution():
n = int(input())
u = mapit()
s = mapit()
skill = {}
for ui, si in zip(u, s):
if ui not in skill:
skill[ui] = [si]
else:
skill[ui].append(si)
for si in skill:
skill[si].sort(reverse=True)
sol = [0] * n
for si in skill:
l = len(skill[si])
for i in range(1, l):
skill[si][i] += skill[si][i - 1]
for k in range(1, l + 1):
f = l - l % k
f -= 1
sol[k - 1] += skill[si][f]
print(*sol)
t = int(input())
while t:
t -= 1
solution() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def solvecaso():
n = int(input())
unis = {}
pertenece = list(map(int, input().split()))
alumnos = list(map(int, input().split()))
for uni in pertenece:
if not uni in unis:
unis[uni] = []
for i in range(n):
unis[pertenece[i]].append(alumnos[i])
unis = [uni[1] for uni in unis.items()]
for uni in unis:
uni.sort(reverse=True)
suma = 0
for i in range(len(uni)):
suma += uni[i]
uni[i] = suma
ks = [(0) for _ in range(n)]
for i in range(1, n + 1):
suma = 0
nuevaunis = []
for uni in unis:
numest = len(uni)
if i > numest:
continue
div = numest // i
suma += uni[i * div - 1]
nuevaunis.append(uni)
unis = nuevaunis
ks[i - 1] = str(suma)
print(" ".join(ks))
return 0
casos = int(input())
for caso in range(1, casos + 1):
result = solvecaso() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT 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 FOR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | class Program:
@staticmethod
def BerlandRegional(n: int, s: list, u: list):
best = []
pr = []
for j in range(n):
best.append([])
pr.append([0])
for j in range(n):
best[s[j] - 1].append(u[j])
for j in range(n):
best[j] = sorted(best[j], reverse=True)
for j in range(n):
for x in best[j]:
pr[j].append(pr[j][-1] + x)
answer = [0] * n
for j in range(n):
for k in range(1, len(best[j]) + 1):
answer[k - 1] += pr[j][int(len(best[j]) / k) * k]
return answer
t = int(input())
for i in range(t):
n = int(input())
s = list(map(int, input().split(" ")))
u = list(map(int, input().split(" ")))
print(" ".join(map(str, Program.BerlandRegional(n, s, u)))) | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
u = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
uni = [[] for i in range(n)]
for i in range(n):
uni[u[i] - 1].append(s[i])
for i in range(n):
uni[i] = sorted(uni[i], reverse=True)
pre = [[] for i in range(n)]
maxi = 0
count = -1
for i in range(n):
maxi = max(maxi, len(uni[i]))
if len(uni[i]) == 0:
continue
count += 1
for j in uni[i]:
if len(pre[count]) == 0:
pre[count].append(j)
else:
pre[count].append(j + pre[count][-1])
pre = sorted(pre, key=lambda x: len(x), reverse=True)
l = [len(pre[i]) for i in range(len(pre))]
for i in range(n):
sz = i + 1
if sz > maxi:
stdout.write(str(0) + " ")
continue
ans = 0
for j in range(count + 1):
if l[j] < sz:
break
to_leave = l[j] % sz
ans += pre[j][l[j] - to_leave - 1]
stdout.write(str(ans) + " ")
stdout.write("\n") | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def solve():
n = int(input())
u = list(map(int, input().split()))
l = list(map(int, input().split()))
d = {}
for i in range(n):
if u[i] in d:
d[u[i]].append(l[i])
else:
e = [l[i]]
d[u[i]] = e
ans = [0] * n
for ii in d:
d[ii].sort(reverse=True)
for i in range(1, len(d[ii])):
d[ii][i] += d[ii][i - 1]
for k in range(1, n + 1):
new = len(d[ii]) // k * k
if new == 0:
break
ans[k - 1] += d[ii][new - 1]
print(*ans)
for testis in range(int(input())):
solve() | 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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | I = lambda: map(int, input().split())
r = range
for t in r(*I()):
(N,) = I()
U = (*I(),)
S = (*I(),)
A = [0] * N
X = [[0] for i in r(N)]
for i in r(N):
X[U[i] - 1] += (S[i],)
for i in r(N):
X[i].sort()
l = len(X[i])
for j in r(1, l):
X[i][j] += X[i][j - 1]
for j in r(1, l):
A[j - 1] += X[i][-1] - X[i][(l - 1) % j]
print(*A) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for t in range(int(input())):
n = int(input())
u = [(int(i) - 1) for i in input().split()]
s = [int(i) for i in input().split()]
us = [[] for i in range(n)]
for i in range(n):
us[u[i]].append(s[i])
ans = [0] * (n + 1)
for j in range(n):
uv = us[j]
ll = len(uv)
if ll == 0:
continue
uv.sort()
ps = [0] * (ll + 1)
for i in range(ll):
ps[i + 1] = ps[i] + uv[i]
tot = ps[-1]
for k in range(1, ll + 1):
ans[k] += tot - ps[ll % k]
print(*ans[1:]) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
univ = [[] for i in range(n + 1)]
for i in range(n):
univ[u[i] - 1].append(s[i])
for i in range(n):
univ[i].sort()
cs = [[0] for i in range(n)]
arr = [0] * (n + 1)
for i in range(n):
cs[i] = [0] + univ[i]
for j in range(len(univ[i])):
cs[i][j + 1] += cs[i][j]
for j in range(1, len(univ[i])):
arr[j] += cs[i][-1] - cs[i][len(univ[i]) % j]
arr[len(univ[i])] += cs[i][-1]
print(*arr[1:]) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
students = list(map(int, input().split()))
strength = list(map(int, input().split()))
combined = sorted(zip(strength, students), reverse=True)
univs = [[] for _ in range(max(students))]
for i in combined:
if len(univs[i[1] - 1]) == 0:
univs[i[1] - 1].append(i[0])
else:
univs[i[1] - 1].append(univs[i[1] - 1][-1] + i[0])
ans = [0] * n
for students in univs:
l = len(students)
for i in range(1, l + 1):
limit = l // i * i
if limit != 0:
ans[i - 1] += students[limit - 1]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | from sys import stdin
input = stdin.buffer.readline
t = int(input())
for i in range(t):
n = int(input())
univ = [int(x) for x in input().split()]
skill = [int(x) for x in input().split()]
arr = [[] for i in range(n + 1)]
for i in range(n):
arr[univ[i]].append(skill[i])
for i in arr:
i.sort(reverse=True)
ans = [0] * (n + 1)
for i in range(1, n + 1):
for j in range(1, len(arr[i])):
arr[i][j] = arr[i][j] + arr[i][j - 1]
k = 1
while k <= len(arr[i]):
x = len(arr[i]) // k * k
ans[k] = ans[k] + arr[i][x - 1]
k = k + 1
print(*ans[1:]) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
d = {}
for i in range(n):
if u[i] in d:
d[u[i]].append(s[i])
else:
d[u[i]] = [s[i]]
for i in d:
d[i] = sorted(d[i], reverse=True)
for j in range(1, len(d[i])):
d[i][j] += d[i][j - 1]
for k in range(1, n + 1):
ans = 0
a = []
for i in d:
l = len(d[i])
ans += d[i][l - l % k - 1]
if l == k:
a.append(i)
for i in a:
del d[i]
print(ans, end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for t in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
res = [[] for i in range(max(u) + 1)]
result = [0] * n
for i in range(n):
res[u[i]].append(s[i])
for item in res:
item.sort()
for i in res:
sum = [0]
s = 0
for j in range(len(i)):
sum.append(sum[-1] + i[j])
s += i[j]
for k in range(1, len(i) + 1):
result[k - 1] += s - sum[len(i) % k]
print(*result) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def updateFinal(final, arr):
total = 0
li = []
arr.sort(reverse=True)
n = len(arr)
for i in range(n):
total += arr[i]
li.append(total)
for i in range(1, n + 1):
final[i - 1] += li[i * (n // i) - 1]
return final
for t in range(int(input())):
n = int(input())
u = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
uniMap = {}
for i in range(n):
if u[i] in uniMap:
uniMap[u[i]].append(s[i])
else:
uniMap[u[i]] = [s[i]]
final = [(0) for x in range(n)]
for key in uniMap:
final = updateFinal(final, uniMap[key])
print(*final) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
d = {}
u = list(map(int, input().split()))
s = list(map(int, input().split()))
for k in range(n):
if u[k] not in d:
d[u[k]] = []
d[u[k]].append(s[k])
for scores in d.values():
scores.sort(reverse=True, key=int)
output = [0] * n
sum_list = {}
for key in d.keys():
scores = d[key]
value = []
total = 0
for score in scores:
total += score
value.append(total)
sum_list[key] = value
for scores in sum_list.values():
for k in range(1, len(scores) + 1):
output[k - 1] += scores[len(scores) // k * k - 1]
print(" ".join(map(str, output))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | T = int(input())
for t in range(T):
n = int(input())
u = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
teams = dict()
for i in range(n):
if u[i] not in teams:
teams[u[i]] = [s[i]]
else:
teams[u[i]].append(s[i])
score = [0] * n
for team in teams:
skill = teams[team]
skill.sort()
c_skill = [0, skill[0]]
for i in range(1, len(skill)):
c_skill.append(skill[i] + c_skill[i])
Sum = sum(skill)
for i in range(len(skill)):
score[i] += Sum - c_skill[len(skill) % (i + 1)]
for i in score:
print(str(i), end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
def solve():
n = int(input())
r = range(n)
u = [(int(x) - 1) for x in input().split()]
s = [int(x) for x in input().split()]
p = [[] for i in r]
st = list(set(u))
for i in r:
p[u[i]].append(s[i])
for i in r:
p[i].sort(reverse=True)
for j in range(1, len(p[i])):
p[i][j] += p[i][j - 1]
ans = [0] * n
for i in r:
good = list()
for elem in st:
b = len(p[elem]) // (i + 1) * (i + 1)
if b != 0:
ans[i] += p[elem][b - 1]
good.append(elem)
st = good
print(*ans)
for tt 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 ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for test in range(int(input())):
n = int(input())
us = list(map(int, input().split()))
s = list(map(int, input().split()))
x = [[] for i in range(n)]
ans = [0] * n
for i in range(n):
x[us[i] - 1].append(s[i])
for i in range(n):
x[i].sort(reverse=True)
for j in range(1, len(x[i])):
x[i][j] += x[i][j - 1]
fig = len(x[i])
for k in range(1, fig + 1):
f = fig - fig % k
ans[k - 1] += x[i][f - 1]
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = [int(d) for d in input().split()]
s = [int(d) for d in input().split()]
d = {}
l = [0] * (n + 1)
for i in range(n):
if u[i] in d:
d[u[i]].append(s[i])
else:
d[u[i]] = [s[i]]
for i in d:
a = d[i]
a.sort()
a.reverse()
b = [0]
c = 0
for j in range(len(a)):
c += a[j]
b.append(c)
for k in range(1, len(a) + 1):
if len(a) % k == 0:
l[k] += c
else:
m = len(a) // k * k
l[k] += b[m]
print(*[l[i] for i in range(1, n + 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | R = lambda: map(int, input().split())
(t,) = R()
while t:
t -= 1
(n,) = R()
r = [0] * n
a = [[0] for _ in r]
for x, y in sorted(zip(R(), R())):
l = a[x - 1]
l += (l[-1] + y,)
for x in a:
for i in range(1, len(x)):
r[i - 1] += x[-1] - x[(len(x) - 1) % i]
print(*r) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
L = [[] for i in range(n + 1)]
for i, j in zip(u, s):
L[i].append(j)
ans = [0] * (n + 1)
for i in range(n + 1):
if L[i] == []:
continue
L[i].sort(reverse=True)
cum = [0]
le = len(L[i])
for j in L[i]:
cum.append(cum[-1] + j)
for j in range(1, n + 1):
if j > le:
break
ans[j] += cum[-1 - le % j]
print(*ans[1:]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for case in range(1, t + 1):
n = int(input())
unis = [int(x) for x in input().split(" ")]
skills = [int(x) for x in input().split(" ")]
students = {}
total = 0
for u, s in zip(unis, skills):
if u in students:
students[u].append(s)
else:
students[u] = [s]
total += s
stop = 0
dp = {}
for u, stu in students.items():
stop = max(len(stu), stop)
if len(stu) not in dp:
dp[len(stu)] = [0] * (len(stu) + 1)
ps = 0
for i, s in enumerate(sorted(stu)):
ps += s
dp[len(stu)][i + 1] += ps
ans = [0] * n
for k in range(1, n + 1):
if k > stop:
break
score = total
for l, ps in dp.items():
mod = l % k
score -= ps[mod]
ans[k - 1] = score
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 DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
u = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
univ = set(u)
d = {int(x): [] for x in univ}
for i in range(n):
d[u[i]].append(s[i])
for k in d.keys():
d[k].sort(reverse=True)
d1 = {}
for key in d.keys():
pr = [0]
for x in d[key]:
pr.append(pr[-1] + x)
d1[key] = pr
for k in range(1, n + 1):
ans = 0
dell = set()
for u in univ:
if len(d[u]) == k:
dell.add(u)
p = len(d[u]) - len(d[u]) % k
ans += d1[u][p]
univ -= dell
print(ans, end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | from sys import stdin
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
u = list(map(int, stdin.readline().split()))
s = list(map(int, stdin.readline().split()))
c = {}
for i in range(n):
if u[i] in c:
c[u[i]].append(s[i])
else:
c[u[i]] = [s[i]]
ar = []
ans = [(0) for i in range(n)]
for i in c:
c[i].sort(reverse=True)
pre = [c[i][0]]
for j in c[i][1:]:
pre.append(pre[-1] + j)
pre = pre[::-1]
l = len(c[i])
for j in range(1, l + 1):
ans[j - 1] += pre[l % j]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR VAR NUMBER FOR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
students = list(map(int, input().split()))
strength = list(map(int, input().split()))
univs = {}
for st, sk in zip(students, strength):
if st not in univs:
univs[st] = [sk]
else:
univs[st].append(sk)
for students in univs:
univs[students].sort(reverse=True)
for students in univs:
l = len(univs[students])
for i in range(1, l):
univs[students][i] += univs[students][i - 1]
ans = [0] * n
for students in univs:
l = len(univs[students])
for i in range(1, l + 1):
limit = l // i * i
if limit != 0:
ans[i - 1] += univs[students][limit - 1]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import itertools
from sys import stdin, stdout
def main():
t = int(stdin.readline())
for __ in range(t):
n = int(stdin.readline())
u = map(int, stdin.readline().split(), itertools.repeat(10, n))
s = map(int, stdin.readline().split(), itertools.repeat(10, n))
students = [list() for __ in range(n)]
for ui, si in zip(u, s):
students[ui - 1].append(si)
ans = [0] * n
for skills in filter(None, students):
skills.sort()
l = len(skills)
partsum = [0] * (l + 1)
for i, si in enumerate(skills):
partsum[i + 1] = partsum[i] + si
for k in range(1, l + 1):
ans[k - 1] += partsum[-1] - partsum[l % k]
stdout.write(" ".join(map(str, ans)))
stdout.write("\n")
main() | IMPORT 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NONE VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
while t:
t -= 1
n = int(input())
u = list(map(int, input().split()))
mx = 1
dic = {}
totsum = 0
for index, value in enumerate(input().split()):
totsum += int(value)
if u[index] not in dic:
dic[u[index]] = [int(value)]
else:
dic[u[index]].append(int(value))
mx = max(len(dic[u[index]]), mx)
ans = [0] * n
for key in dic:
dic[key].sort()
s = dic[key][0]
ln = len(dic[key])
for i in range(1, len(dic[key])):
dic[key][i] = dic[key][i] + s
s = dic[key][i]
for i in range(1, ln + 1):
re = ln % i
if re == 0:
ans[i - 1] += dic[key][ln - 1]
else:
ans[i - 1] += dic[key][ln - 1] - dic[key][re - 1]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for t in range(int(input())):
n = int(input())
u = tuple(map(int, input().split()))
s = tuple(map(int, input().split()))
d = dict()
for i in range(n):
if u[i] not in d:
d[u[i]] = [s[i]]
else:
d[u[i]].append(s[i])
l = [0] * n
for i in d:
a = sorted(d[i])[::-1]
b = []
c = 0
for j in range(len(a)):
c += a[j]
b.append(c)
for k in range(1, len(a) + 1):
m = len(a) - len(a) % k
l[k - 1] += b[m - 1]
print(*l) | 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = sys.stdin.readline
def println(val):
sys.stdout.write(str(val) + "\n")
for _ in range(int(input().strip())):
N = int(input().strip())
U = [int(x) for x in input().strip().split()]
S = [int(x) for x in input().strip().split()]
varsities = [[] for i in range(N + 1)]
for i, u, s in zip(range(N), U, S):
varsities[u] += [s]
ans = [(0) for i in range(N)]
for i, varsity in enumerate(varsities):
if len(varsity) == 0:
continue
varsity.sort(reverse=True)
pref = [varsity[0]]
for ii in range(1, len(varsity)):
pref += [pref[-1] + varsity[ii]]
for ii in range(1, len(varsity) + 1):
ans[ii - 1] += pref[len(varsity) - len(varsity) % ii - 1]
println(" ".join(str(a) for a in ans)) | IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR LIST BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def answer(n, u, s):
record = [[] for i in range(n)]
for i in range(n):
record[u[i] - 1].append(s[i])
for i in range(n):
record[i].sort(reverse=True)
record[i] = len(record[i]), [], record[i]
l = record[i][2]
length = record[i][0]
if length != 0:
record[i][1].append(l[0])
for j in range(1, length):
record[i][1].append(l[j] + record[i][1][-1])
record.sort(reverse=True)
for k in range(1, n + 1):
ans = 0
for i in range(n):
length = record[i][0]
if length < k:
break
else:
remainder = length % k
ans += record[i][1][length - 1 - remainder]
print(ans, end=" ")
print("")
t = int(input())
for i in range(t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
answer(n, u, s) | FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
ns = int(input())
us = [int(d) for d in input().split()]
s = [int(d) for d in input().split()]
d = {}
for i in range(ns):
if us[i] in d:
d[us[i]].append(s[i])
else:
d[us[i]] = [s[i]]
l = [0] * (ns + 1)
for i in d:
a = d[i]
a.sort()
a.reverse()
b = [0]
c = 0
for j in range(len(a)):
c += a[j]
b.append(c)
for k in range(1, len(a) + 1):
if len(a) % k == 0:
l[k] += c
else:
m = len(a) // k * k
l[k] += b[m]
for i in range(1, ns + 1):
print(l[i], end=" ")
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
uni = list(map(int, input().split()))
strength = list(map(int, input().split()))
l2d = dict()
for i in range(n):
if uni[i] in l2d.keys():
l2d[uni[i]].append(strength[i])
else:
l2d[uni[i]] = [strength[i]]
uni = set(uni)
ans = [0] * n
for i in uni:
l2d[i].sort(reverse=True)
arr = []
c = 0
sz = len(l2d[i])
for j in range(len(l2d[i])):
c += l2d[i][j]
arr.append(c)
for k in range(1, n + 1):
if k > sz:
break
ans[k - 1] += arr[sz - sz % k - 1]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = sys.stdin.readline
def solve():
n = int(input())
U = list(map(int, input().split()))
S = list(map(int, input().split()))
univ = [[] for _ in range(n + 1)]
ps = {}
for i in range(n):
univ[U[i]].append(S[i])
for i in range(1, n + 1):
univ[i].sort()
m = len(univ[i])
ps[i] = []
curr = 0
for j in range(m):
curr += univ[i][j]
ps[i].append(curr)
ans = [0] * (n + 1)
for i in range(1, n + 1):
m = len(univ[i])
for j in range(1, m + 1):
r = m % j
if r == 0:
ans[j] += ps[i][-1]
else:
ans[j] += ps[i][-1] - ps[i][r - 1]
return ans[1:]
for _ in range(int(input())):
print(*solve()) | IMPORT ASSIGN 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 LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
uni = dict()
for i in range(n):
if u[i] not in uni:
uni[u[i]] = [s[i]]
else:
uni[u[i]].append(s[i])
res = {z: (0) for z in range(1, n + 1)}
for key in uni:
uni[key].sort(reverse=True)
for x in range(1, len(uni[key])):
uni[key][x] += uni[key][x - 1]
for k in range(1, n + 1):
index = len(uni[key]) // k * k - 1
if index == -1:
break
res[k] += uni[key][index]
print(*res.values()) | 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | def solve():
J = int(input())
for O in range(J):
F = int(input())
K = map(int, input().split())
L = map(int, input().split())
B = {}
for C, M in zip(K, L):
if C not in B:
B[C] = []
B[C].append(M)
for A in B.values():
A.sort(reverse=True)
for A in B.values():
for G in range(1, len(A)):
A[G] += A[G - 1]
H = [0] * F
for A in B.values():
for D in range(1, F + 1):
I = 0
E = len(A) // D
if E == 0:
break
if E > 0:
N = A[E * D - 1]
I += N
H[D - 1] += I
print(" ".join([str(A) for A in H]))
solve() | 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
universities = {}
for i in range(n):
if u[i] in universities:
universities[u[i]].append(s[i])
else:
universities[u[i]] = [s[i]]
for i in universities:
universities[i].sort(reverse=True)
psum = [0]
for j in range(len(universities[i])):
psum.append(psum[-1] + universities[i][j])
universities[i] = psum
for k in range(1, n + 1):
remove = []
tot = 0
for i in universities:
for j in range(k, len(universities[i]), k):
tot += universities[i][j] - universities[i][j - k]
if len(universities[i]) == k:
remove.append(i)
for i in remove:
universities.pop(i)
print(tot, end=" ")
print() | IMPORT ASSIGN 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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
su = dict()
for i, e in zip(u, s):
su.setdefault(i, []).append(e)
ans = [0] * len(u)
for i in su:
l = su[i]
l.sort(reverse=True)
for j in range(1, len(l)):
l[j] += l[j - 1]
for k in range(1, len(l) + 1):
r = len(l) % k
ans[k - 1] += l[len(l) - r - 1]
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
uni = list(map(int, input().split()))
arr = list(map(int, input().split()))
mapper = [[] for i in range(n)]
for i in range(n):
mapper[uni[i] - 1].append(arr[i])
for i in range(n):
temp = mapper[i]
temp.sort(reverse=True)
mapper[i] = temp
ans = [(0) for i in range(n + 5)]
for i in range(n):
cur = mapper[i]
k = len(cur)
pre = []
for j in range(k):
if j == 0:
pre.append(cur[j])
else:
pre.append(pre[-1] + cur[j])
for j in range(1, k + 1):
rem = k % j
ans[j] += pre[k - rem - 1]
for i in range(1, n + 1):
print(ans[i], end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | from itertools import accumulate
def solve(u, s, n):
res = [0] * n
l = [[] for i in range(n)]
for i in range(n):
l[u[i] - 1].append(s[i])
for i in range(n):
l[i].sort(reverse=True)
l[i] = list(accumulate(l[i]))
for j in range(len(l)):
le = len(l[j])
for i in range(1, n + 1):
if le >= i:
if le % i == 0:
res[i - 1] += l[j][-1]
else:
res[i - 1] += l[j][le - le % i - 1]
else:
break
print(*res)
for i in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
solve(u, s, n) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
urr = list(map(int, input().split()))
for i in range(n):
urr[i] -= 1
srr = list(map(int, input().split()))
mapper = [[] for i in range(n)]
for i in range(n):
mapper[urr[i]].append(srr[i])
for i in range(n):
temp = mapper[i]
temp.sort(reverse=True)
mapper[i] = temp
ans = [(0) for i in range(n + 5)]
for i in range(n):
k = len(mapper[i])
if k == 0:
continue
for j in range(k - 2, -1, -1):
mapper[i][j] += mapper[i][j + 1]
for g in range(1, k + 1):
rem = k % g
if rem > 0:
ans[g] -= mapper[i][k - rem]
ans[g + 1] += mapper[i][k - rem]
ans[k + 1] -= mapper[i][0]
total = sum(srr)
for i in range(1, n + 5):
ans[i] += ans[i - 1]
for i in range(n + 5):
ans[i] += total
for i in range(1, n + 1):
print(ans[i], end=" ")
print() | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = iter(sys.stdin.read().splitlines()).__next__
def solve():
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
university_skills = [[] for _ in range(n)]
for skill, uni in zip(s, u):
university_skills[uni - 1].append(skill)
for skills in university_skills:
skills.sort(reverse=True)
university_teams = [[0] for _ in range(n)]
for skills, team in zip(university_skills, university_teams):
for student_skill in skills:
team.append(team[-1] + student_skill)
university_teams.sort(key=len, reverse=True)
strengths = []
for k in range(1, n + 1):
strength = 0
for uni in range(len(university_teams) - 1, -1, -1):
if len(university_teams[uni]) < k + 1:
university_teams.pop()
else:
num_students = len(university_teams[uni]) - 1
num_teams = num_students // k
strength += university_teams[uni][k * num_teams]
strengths.append(strength)
return " ".join(map(str, strengths))
t = int(input())
output = []
for _ in range(t):
output.append(solve())
print(*output, sep="\n") | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | from sys import stdin
def read_int():
return int(stdin.readline())
def read_ints():
return map(int, stdin.readline().split(" "))
t = read_int()
for case_num in range(t):
n = read_int()
u = list(read_ints())
s = list(read_ints())
tot = sum(s)
d = [[] for _ in range(n + 1)]
for ui, si in zip(u, s):
d[ui].append(si)
for i in range(1, n + 1):
d[i].sort()
acc = [([0] * (len(d[i]) + 1)) for i in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, len(d[i]) + 1):
acc[i][j] = acc[i][j - 1] + d[i][j - 1]
ans = []
rem = set([i for i in range(1, n + 1) if len(d[i]) > 0])
for k in range(1, n + 1):
dec = 0
to_remove = set()
for i in rem:
if len(d[i]) < k:
to_remove.add(i)
tot -= sum(d[i])
else:
dec += acc[i][len(d[i]) % k]
ans.append(tot - dec)
for i in to_remove:
rem.remove(i)
print(" ".join(map(str, ans))) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
dp = dict()
for i in range(n):
try:
dp[u[i]].append(s[i])
except:
dp[u[i]] = []
dp[u[i]].append(s[i])
op = 0
ans = [(0) for i in range(n + 1)]
for i in dp:
dp[i].sort(reverse=True)
halp = [0]
for x in dp[i]:
halp.append(halp[-1] + x)
for j in range(1, len(halp)):
ans[j] += halp[len(dp[i]) // j * j]
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 FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
dic = {}
for i in range(n):
k = u[i]
if k in dic:
dic[k].append(s[i])
else:
dic[k] = [s[i]]
o = set(u)
ans = [0] * n
for i in o:
dic[i].sort()
dic[i].reverse()
v = len(dic[i])
hold = []
c = 0
for j in range(len(dic[i])):
c += dic[i][j]
hold.append(c)
for j in range(1, n + 1):
if j > v:
break
else:
ran = v // j * j
ans[j - 1] += hold[ran - 1]
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
for i in range(int(input())):
n = int(input())
z = list(map(int, input().split()))
s = list(map(int, input().split()))
d = {}
for i in range(n):
if z[i] in d:
d[z[i]].append(s[i])
else:
d[z[i]] = [s[i]]
m = {}
for i in d.keys():
d[i].sort(reverse=True)
m[i] = len(d[i])
for k in range(1, len(d[i])):
d[i][k] += d[i][k - 1]
x = set()
a = [0] * n
for k in range(1, n + 1):
ans = 0
if d == {}:
break
for i in list(d.keys()):
z = m[i] // k * k
if z != 0:
ans += d[i][z - 1]
if m[i] <= k:
del d[i]
a[k - 1] = ans
for i in a:
print(i, end=" ")
print() | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | import sys
input = sys.stdin.buffer.readline
L = lambda: list(map(int, input().split()))
tc = int(input())
for _ in range(tc):
n = int(input())
u = L()
s = L()
unis = [[0] for _ in range(n + 1)]
for i in range(n):
unis[u[i]].append(s[i])
ans = [0] * n
for i in range(n + 1):
c = len(unis[i]) - 1
if c:
unis[i].sort()
for j in range(1, c + 1):
unis[i][j] = unis[i][j - 1] + unis[i][j]
for j in range(1, c + 1):
ans[j - 1] += unis[i][c] - unis[i][c % j]
print(*ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp is an organizer of a Berland ICPC regional event. There are $n$ universities in Berland numbered from $1$ to $n$. Polycarp knows all competitive programmers in the region. There are $n$ students: the $i$-th student is enrolled at a university $u_i$ and has a programming skill $s_i$.
Polycarp has to decide on the rules now. In particular, the number of members in the team.
Polycarp knows that if he chooses the size of the team to be some integer $k$, each university will send their $k$ strongest (with the highest programming skill $s$) students in the first team, the next $k$ strongest students in the second team and so on. If there are fewer than $k$ students left, then the team can't be formed. Note that there might be universities that send zero teams.
The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $0$.
Help Polycarp to find the strength of the region for each choice of $k$ from $1$ to $n$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) β the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of universities and the number of students.
The second line of each testcase contains $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le n$) β the university the $i$-th student is enrolled at.
The third line of each testcase contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \le s_i \le 10^9$) β the programming skill of the $i$-th student.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase print $n$ integers: the strength of the region β the total skill of the members of the present teams β for each choice of team size $k$.
-----Examples-----
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0
24907 20705 22805 9514 0 0 0 0 0 0
43 43 43 32 38 43
3083
-----Note-----
In the first testcase the teams from each university for each $k$ are:
$k=1$:
university $1$: $[6], [5], [5], [3]$;
university $2$: $[8], [1], [1]$;
$k=2$:
university $1$: $[6, 5], [5, 3]$;
university $2$: $[8, 1]$;
$k=3$:
university $1$: $[6, 5, 5]$;
university $2$: $[8, 1, 1]$;
$k=4$:
university $1$: $[6, 5, 5, 3]$; | t = int(input())
for _ in range(t):
n = int(input())
u = list(map(int, input().split()))
s = list(map(int, input().split()))
d = {}
for i in range(n):
if u[i] not in d:
d[u[i]] = [s[i]]
else:
d[u[i]].append(s[i])
res = [0] * n
mx = -1
for i in d:
a = d[i]
a.sort(reverse=True)
for j in range(len(a)):
if j != 0:
a[j] += a[j - 1]
mx = max(len(a), mx)
for i in d:
a = d[i]
ln = len(a)
for x in range(1, ln + 1):
ix = ln % x
if ln >= x:
res[x - 1] += a[ln - ix - 1]
print(*res) | 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 FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
candy = 0
while True:
endCycle = True
roundMoney = 0
roundCandy = 0
for x in a:
if T >= x:
endCycle = False
T -= x
roundMoney += x
roundCandy += 1
if roundMoney:
candy += roundCandy * (T // roundMoney + 1)
T %= roundMoney
if endCycle or T == 0:
print(candy)
break | 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 NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()]]
k = 0
na = 0
ma = 1
while t >= ma:
sa = sum(a[na])
la = len(a[na])
if t >= sa:
k += la * (t // sa)
t %= sa
ma = min(a[na])
a.append([])
for ta in a[na]:
if t >= ta:
t -= ta
k += 1
a[na + 1].append(ta)
na += 1
print(k) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
A = [int(x) for x in input().split()]
result = 0
bought_any = True
while True:
bought_any = False
amount, value = 0, 0
for x in A:
if x <= t:
t -= x
amount += 1
value += x
bought_any = True
if not bought_any:
break
k = t // value
t %= value
result += (k + 1) * amount
print(result) | 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 NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = list(map(int, input().split()))
a = [int(x) for x in input().split()]
otv = 0
def rec(t, a):
nonlocal otv
s = 0
for c in a:
s += c
kol = t // s
kol = max(kol, 0)
otv += kol * len(a)
octat = t - kol * s
res = []
su = 0
for c in a:
if su + c <= octat:
res.append(c)
su += c
if su == 0:
print(otv)
return
rec(octat, res)
rec(t, a) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
a = list(map(int, input().split()))
sum1 = 0
for i in range(n):
sum1 += a[i]
b = t % sum1
bought = t // sum1 * n
k = 0
l = min(a)
gone = [0] * n
while b >= l:
for i in range(n):
if a[i] > b and gone[i] == 0:
k += 1
gone[i] = 1
sum1 -= a[i]
bought += b // sum1 * (n - k)
b = b % sum1
if b // sum1 == 0:
for i in range(n):
if a[i] <= b:
bought += 1
b -= a[i]
print(bought) | 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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
while t > 0:
sum = 0
cnt = 0
cur = t
for i in range(n):
if a[i] <= cur:
sum += a[i]
cnt += 1
cur -= a[i]
if cnt == 0:
break
ans += cnt * (t // sum)
t %= sum
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 NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
s0 = 0
b = sorted(a, reverse=True)
big = b[0]
s = []
s0 = sum(b)
for i in b:
s.append(s0)
s0 -= i
money = t
ans = 0
for i, total in enumerate(s):
big1 = b[i]
if money >= total:
ans += (n - i) * (money // total)
money -= total * (money // total)
if money < big1:
continue
else:
while money >= big1:
f1 = True
for ls in range(n):
if money - a[ls] >= 0:
money -= a[ls]
f1 = False
ans += 1
else:
pass
ls += 1
if f1 == True:
break
if f1 == True:
break
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, m = list(map(int, input().split()))
l = list(map(int, input().split()))
minimum = min(l)
ans = 0
while m >= minimum:
c = t = 0
for i in l:
if i + t <= m:
t += i
c += 1
ans += m // t * c
m %= t
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
a = list(map(int, input().split()))
result = 0
min_ = t
a_ = a
while t >= min_:
loop_sum = 0
next_a = []
for el in a_:
if t - loop_sum >= el:
loop_sum += el
next_a.append(el)
min_ = min(min_, el)
if t == loop_sum:
break
if len(next_a) == 0:
break
else:
a_ = next_a
loops = t // loop_sum
result += len(next_a) * loops
t -= loops * loop_sum
print(result) | 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 NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)
def read_int():
return int(stdin.readline())
def read_ints():
return [int(x) for x in stdin.readline().split()]
def read_str():
return input()
def read_strs():
return [x for x in stdin.readline().split()]
nb_shop, has_amt = read_ints()
prices = read_ints()
sums = sum(prices)
ans = 0
size = nb_shop
while size:
curr, has_amt = divmod(has_amt, sums)
ans += curr * size
sums = 0
for i in range(nb_shop):
if sums + prices[i] > has_amt:
prices[i] = 0
size -= 1
sums += prices[i]
print(ans) | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
a = list(map(int, input().split()))
mn = min(a)
ans = 0
while t >= mn:
k = t
m = 0
for i in range(n):
if a[i] <= k:
k -= a[i]
m += 1
r = t // (t - k)
ans += r * m
t -= (t - k) * r
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
a = list(map(int, input().split()))
suma = sum(a)
a = {i: a[i] for i in range(n)}
ans = 0
c = 0
left = n
while suma != 0:
ans += t // suma * left
t = t % suma
while suma > t:
if c in a:
if t < a[c]:
suma -= a[c]
left -= 1
del a[c]
else:
t -= a[c]
ans += 1
c = (c + 1) % n
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 FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, tot = map(int, input().split())
arr = list(map(int, input().split()))
p = tot
can = 0
while 1:
temp = 0
cnt = 0
for i in range(n):
if temp + arr[i] <= p:
temp += arr[i]
cnt += 1
if cnt == 0:
break
can += p // temp * cnt
p = p % temp
print(can) | 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 ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | def update(indx):
sgn_tree[indx] = 0
indx = indx >> 1
while indx >= 1:
sgn_tree[indx] = sgn_tree[indx << 1] + sgn_tree[(indx << 1) + 1]
indx = indx >> 1
def queries(l, r):
add = 0
while l <= r:
if l % 2 == 1:
add += sgn_tree[l]
l += 1
if r % 2 == 0:
add += sgn_tree[r]
r -= 1
l = l >> 1
r = r >> 1
return add
n, cost = map(int, input().split())
a = list(map(int, input().split()))
sgn_tree = [0] * (2 * n)
for i in range(n, 2 * n):
sgn_tree[i] = a[i - n]
for i in range(n - 1, 0, -1):
sgn_tree[i] = sgn_tree[i << 1] + sgn_tree[(i << 1) + 1]
i = 0
count = 0
while i < n:
if cost >= sgn_tree[1]:
count += cost // sgn_tree[1] * (n - i)
cost = cost % sgn_tree[1]
l, r = n, 2 * n - 1
while l < r:
m = (l + r) // 2
if queries(n, m) <= cost:
l = m + 1
else:
r = m - 1
if queries(n, l) <= cost:
update(l + 1)
else:
update(l)
i += 1
print(count) | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP 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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, T = map(int, input().split())
L = list(map(int, input().split()))
res = 0
while len(L) > 0:
s = sum(L)
l = len(L)
r = T // s
res += r * l
T -= r * s
a = []
for i in L:
if T >= i:
T -= i
res += 1
a.append(i)
L = a
print(res) | 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 NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | x, cost = map(int, input().split())
z = list(map(int, input().split()))
total = 0
mini = min(z)
c1 = 0
item = 0
while cost >= mini:
total = 0
for i in range(len(z)):
if total + z[i] <= cost:
total += z[i]
c1 += 1
sets = cost // total
item += sets * c1
cost = cost % total
sets = 0
total = 0
c1 = 0
print(item) | 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, t = map(int, input().split())
cost = [int(x) for x in input().split()]
mn, ans = min(cost), 0
while t >= mn:
val, cnt, curr_money = 0, 0, t
for i in range(0, len(cost)):
if t >= cost[i]:
t -= cost[i]
val += cost[i]
cnt += 1
ans += curr_money // val * cnt
t %= val
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | def func(n, t, a):
count = 0
s = sum(a)
z = []
if t >= s:
count += t // s * n
t %= s
for i in a:
if t >= i:
z.append(i)
count += 1
t -= i
if t >= min(a):
count += func(len(z), t, z)
return count
n, t = map(int, input().split())
a = list(map(int, input().split()))
print(func(n, t, a)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | def main():
N, money = list(map(int, input().split()))
candies = list(map(int, input().split()))
number_of_candies_bought = 0
current_money = money
while True:
current_number_of_candies_bought = 0
total_price = 0
for candy in candies:
if total_price + candy <= current_money:
current_number_of_candies_bought += 1
total_price += candy
if current_number_of_candies_bought == 0:
break
number_of_iteration = current_money // total_price
number_of_candies_bought += (
number_of_iteration * current_number_of_candies_bought
)
current_money -= number_of_iteration * total_price
print(number_of_candies_bought)
main() | FUNC_DEF 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 NUMBER ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | def get(tn, arr):
st = cnt = 0
for i in arr:
if tn >= i:
tn -= i
st += i
cnt += 1
return st, cnt
n, t = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
mm = min(a)
final = 0
while t >= mm:
st, cnt = get(t, a)
final += cnt * (t // st)
t = t % st
print(final) | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | n, T = list(map(int, input().split()))
A = list(map(int, input().split()))
AIND = [(A[i], i) for i in range(n)]
AS = sorted(AIND)
MINA = AS[0][0]
SUM = [AS[0][0]]
for i in range(1, n):
SUM.append(AS[i][0] + SUM[-1])
SUM.reverse()
AS.reverse()
MAX = SUM[0]
x = 0
ANS = 0
while T >= MINA:
if T > SUM[x]:
ANS += (n - x) * (T // SUM[x])
T = T % SUM[x]
elif T < AS[x][0]:
x += 1
else:
for i in range(n):
if T >= A[i]:
T -= A[i]
ANS += 1
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 VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | def f(lst, b):
ans = 0
while b:
flag = True
cmin = 0
l = 0
for i in lst:
if b and i <= b:
b -= i
ans += 1
cmin += i
l += 1
flag = False
if cmin:
l2 = b // cmin * cmin
ans += l * (b // cmin)
b -= l2
if flag:
break
return ans
a, b = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
print(f(lst, b)) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR RETURN VAR 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 FUNC_CALL VAR VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | booths, money = map(int, input().split())
prices = list(map(int, input().split()))
ans = 0
sum_prices = sum(prices)
while len(prices) > 0:
ans += booths * (money // sum_prices)
money %= sum_prices
r = []
sum_prices = 0
booths = 0
for p in prices:
if money >= p:
money -= p
ans += 1
r.append(p)
sum_prices += p
booths += 1
prices = r
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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
-----Input-----
The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) β the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the price of the single candy at booth number $i$.
-----Output-----
Print a single integer β the total number of candies Polycarp will buy.
-----Examples-----
Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6
-----Note-----
Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$.
No candy can be bought later. The total number of candies bought is $10$.
In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. | In = lambda: map(int, input().split())
n, T = In()
a = list(In())
ans = 0
minv = min(a)
while T >= minv:
count = 0
t = T
for v in a:
if t >= v:
count += 1
t -= v
s = T - t
d = T // s
ans += d * count
T -= s * d
print(ans) | 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.