description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
dic = {}
n = int(input())
ls = list(map(int, input().split()))
arr = [0] * (n + 1)
ans = []
dic = {}
count = 0
num = 0
for i in range(n):
if ls[i] > n:
count = n + 1
break
if arr[ls[i]] == 0:
num += 1
dic[ls[i]] = num
arr[ls[i]] = ls[i] - 1
count += ls[i]
ans.append(num)
else:
ans.append(dic[ls[i]])
arr[ls[i]] -= 1
if count != n:
print(-1)
else:
print(*ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
d = {}
for i in range(n):
if b[i] not in d:
d[b[i]] = 1
else:
d[b[i]] += 1
nums = 0
for i in d:
nums += d[i] / i
if nums % 1 != 0:
print(-1)
continue
else:
nums = int(nums)
ans = [(0) for i in range(len(b))]
num = 0
d1 = {}
d2 = {}
for i in range(len(b)):
if b[i] not in d1:
num += 1
d1[b[i]] = num
d2[num] = 1
ans[i] = num
elif d2[d1[b[i]]] % b[i] != 0:
ans[i] = d1[b[i]]
d2[d1[b[i]]] += 1
else:
num += 1
d1[b[i]] = num
d2[num] = 1
ans[i] = d1[b[i]]
for i in ans:
print(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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
a = [(-1) for i in range(n)]
dic = {}
for i in range(n):
if b[i] in dic:
dic[b[i]].append(i)
else:
dic[b[i]] = [i]
yes = 1
for i in dic.keys():
if len(dic[i]) % i:
yes = 0
break
if yes == 0:
print("-1")
continue
num = 1
for i in range(n):
if a[i] != -1:
continue
for j in range(b[i]):
a[dic[b[i]][0]] = str(num)
dic[b[i]].pop(0)
num += 1
print(" ".join(a)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | T = int(input())
for t in range(0, T):
L = int(input())
B = list(map(int, input().split()))
A = []
EH = {}
FH = {}
a = 1
for i in B:
if i in EH:
A.append(EH[i])
FH[i] += 1
if FH[i] == i:
del EH[i]
del FH[i]
continue
else:
A.append(a)
if i == 1:
a += 1
continue
else:
EH[i] = a
FH[i] = 1
a += 1
continue
if not EH:
print(*A)
else:
print(-1) | 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 LIST ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | t = int(input())
while t:
n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in range(len(arr)):
if arr[i] not in d:
d[arr[i]] = [i]
else:
d[arr[i]].append(i)
s = 0
for i in d:
if len(d[i]) % i != 0:
s = -1
break
s += len(d[i])
if s != n:
print(-1)
else:
l = [0] * n
j = 1
for i in range(len(arr)):
if l[i] == 0:
x = d[arr[i]]
y = arr[i]
for k in x:
if y > 0:
l[k] = j
y -= 1
else:
break
del x[0 : arr[i]]
j += 1
else:
continue
[print(i, end=" ") for i in l]
print()
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
d, ans, cnt, impossible = dict(), [], 1, False
for i in range(n):
if d.get(b[i], [0, 0])[1] == 0:
d[b[i]] = [cnt, b[i] - 1]
cnt += 1
else:
d[b[i]][1] -= 1
ans.append(str(d[b[i]][0]))
for k in d.keys():
if d[k][1] > 0:
impossible = True
break
print(" ".join(ans) if not impossible else -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 VAR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR NUMBER |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | import sys
from itertools import islice
for s in islice(sys.stdin, 2, None, 2):
a = []
d = {}
i = 0
for x in map(int, s.split()):
if (y := d.get(x)) is None:
y = d[x] = [(i := i + 1), x]
a.append(y[0])
y[1] -= 1
if y[1] == 0:
del d[x]
print(*([-1] if d else a)) | IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR LIST NUMBER VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | testcases = int(input())
for i in range(testcases):
n = int(input())
data = list(map(int, input().split()))
flag = 0
check = {}
for i in data:
if i in check:
check[i] += 1
else:
check[i] = 1
for i in check:
if check[i] % i != 0:
flag = 1
if flag == 1:
print(-1)
else:
datacount = {}
dataassign = {}
j = 1
val = []
for i in data:
if i not in datacount:
datacount[i] = 1
dataassign[i] = j
val.append(j)
if datacount[i] == i:
del datacount[i]
j = j + 1
else:
datacount[i] += 1
val.append(dataassign[i])
if datacount[i] == i:
del datacount[i]
print(*val) | 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 NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | T = int(input())
while T:
T -= 1
n = int(input())
b = list(map(int, input().split()))
d = {b[0]: [1]}
numsl = [0, b[0] - 1]
if not numsl[1]:
del d[b[0]][0]
ans = [1]
num = 2
if n == 1:
print(1)
else:
for i in b[1:]:
if i not in d or not d[i]:
if i - 1:
d[i] = [num]
ans.append(num)
num += 1
numsl.append(i - 1)
else:
ans.append(d[i][0])
numsl[d[i][0]] -= 1
if not numsl[d[i][0]]:
del d[i][0]
if sum(numsl):
print(-1)
else:
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 DICT VAR NUMBER LIST NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = set(a)
b = dict.fromkeys(b, 0)
for i in a:
b[i] += 1
res = True
for i in b:
if b[i] % i != 0:
print(-1)
res = False
break
if res == True:
j = 1
l = [0] * n
dic = {}
for i in range(n):
if b[a[i]] % a[i] == 0:
dic[a[i]] = j
j += 1
b[a[i]] -= 1
l[i] = dic[a[i]]
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 VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
_ = input()
b = list(map(int, input().split()))
updated = set()
num = 1
for i in range(len(b)):
if i in updated:
continue
bi = b[i]
b[i] = num
updated.add(i)
changed = 1
for j in range(i + 1, len(b)):
if j in updated:
continue
if changed == bi:
break
if b[j] == bi:
b[j] = num
updated.add(j)
changed += 1
if changed != bi:
print(-1)
break
num += 1
else:
print(" ".join([str(i) for i in b])) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | def solve():
flag = 0
n = int(input())
arr = list(map(int, input().split()))
freq = dict()
for i in arr:
if i not in freq.keys():
freq[i] = 0
freq[i] += 1
for i in freq.keys():
if freq[i] % i != 0:
print(-1)
return
m = {}
f = {}
j = 1
for i in arr:
if i not in m.keys() or i not in f.keys() or f[i] == 0:
m[i] = j
j += 1
f[i] = i
print(m[i], end=" ")
f[i] -= 1
print()
try:
t = int(input())
while t > 0:
solve()
t -= 1
except:
pass | FUNC_DEF ASSIGN 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 FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for i in range(int(input())):
n = int(input())
B = [int(j) for j in input().split()]
u = {}
k = 1
for j in range(n):
if B[j] not in u:
u[B[j]] = [1, k]
k += 1
else:
if u[B[j]][0] % B[j] == 0:
u[B[j]].append(k)
k += 1
u[B[j]][0] += 1
b = True
for j in u:
if u[j][0] % j != 0:
b = False
break
if b:
k = 1
for j in B:
print(u[j][1], end=" ")
u[j][0] -= 1
if u[j][0] % j == 0:
u[j].pop(1)
print()
else:
print(-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 DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
n = int(input())
nl = [int(x) for x in input().split()]
dic = {}
for i in nl:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
flag = 0
for i in nl:
if dic[i] % i != 0:
flag = 1
break
if flag:
print(-1)
else:
aa = {}
bc = {}
j = 1
arr = []
for i in nl:
if i in aa:
arr += [bc[i]]
aa[i] += 1
if aa[i] == i:
del aa[i]
else:
aa[i] = 1
bc[i] = j
arr += [j]
if aa[i] == i:
del aa[i]
j += 1
for i in range(n):
print(arr[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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR LIST VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR LIST VAR IF VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | NumTests = int(input())
for test in range(NumTests):
N = int(input())
B = list(map(int, input().split(" ")))
freqdict = {}
for b in B:
if b in freqdict.keys():
freqdict[b] += 1
else:
freqdict[b] = 1
flag = "Pass"
for k in freqdict:
if freqdict[k] % k != 0:
flag = "Fail"
break
if flag == "Fail":
print(-1)
continue
Result = []
nextfree = 1
trackerdict1 = {}
trackerdict2 = {}
for b in B:
if b in trackerdict1.keys():
Result.append(trackerdict1[b])
trackerdict2[b] -= 1
else:
trackerdict1[b] = nextfree
trackerdict2[b] = b - 1
Result.append(nextfree)
nextfree += 1
if trackerdict2[b] == 0:
del trackerdict2[b]
del trackerdict1[b]
for r in Result:
print(r, 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 STRING ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | tpy = int(input())
for i in range(tpy):
n = int(input())
b = list(map(int, input().split()))
a = []
c = {}
d = 1
for j in range(n):
if b[j] not in c.keys():
c[b[j]] = [d, b[j] - 1]
d = d + 1
a.append(c[b[j]][0])
else:
a.append(c.get(b[j])[0])
l = c.get(b[j])
l[1] = l[1] - 1
c[b[j]] = l
if c.get(b[j])[1] < 1:
del c[b[j]]
if bool(c) == True:
a.clear()
a.append(-1)
print(" ".join(map(str, a))) | 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 LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | t = int(input())
for i in range(t):
x = int(input())
flag = 0
list1 = list(map(int, input().split()))
dict1 = {}
num = []
ans = []
for j in range(len(list1)):
num.append(j + 1)
if list1[j] not in dict1:
dict1[list1[j]] = 1
else:
dict1[list1[j]] += 1
for k in dict1.keys():
if dict1[k] % k != 0:
flag = -1
break
if flag != -1:
q = 0
dict3 = {}
dict2 = {}
x = []
for r in range(len(list1)):
x = dict2.keys()
if list1[r] not in x:
dict3[list1[r]] = num[q]
dict2[list1[r]] = 1
ans.append(num[q])
q += 1
if list1[r] == 1:
del dict3[list1[r]]
del dict2[list1[r]]
elif list1[r] > dict2[list1[r]]:
ans.append(dict3[list1[r]])
dict2[list1[r]] += 1
if dict2[list1[r]] == list1[r]:
del dict3[list1[r]]
del dict2[list1[r]]
print(*ans)
else:
print("-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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for i in range(0, int(input())):
n = int(input())
a = list(map(int, list(input().split())))
d = {}
ans = []
count = 1
for j in range(0, n):
if a[j] in d.keys():
ans.append(d[a[j]][0])
else:
d[a[j]] = [[count, a[j]]]
count += 1
ans.append(d[a[j]][0])
d[a[j]][0][1] -= 1
if d[a[j]][0][1] == 0:
del d[a[j]]
if len(d) != 0:
print(-1)
else:
for j in range(n):
print(ans[j][0], " ", end="")
print("\n") | FOR VAR FUNC_CALL VAR NUMBER 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR LIST LIST VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR STRING |
Consider an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequency* of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the *frequency array* B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1β€ A_{i} β€ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N β the size of the array.
- The next line contains N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}, the frequency array.
------ Output Format ------
For each test case, output on a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array. | for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
elem = {}
cnt = {}
num = 1
ans = [(0) for i in range(n)]
for i in range(n):
if a[i] not in elem:
elem[a[i]] = num
cnt[num] = 1
ans[i] = num
num += 1
else:
e = elem[a[i]]
if cnt[e] % a[i] != 0:
ans[i] = e
cnt[e] += 1
else:
ans[i] = num
elem[a[i]] = num
cnt[num] = 1
num += 1
temp = {}
for e in ans:
temp[e] = temp.get(e, 0) + 1
f = 0
for i in range(n):
if a[i] != temp[ans[i]]:
f = 1
break
if f == 0:
print(*ans)
else:
print(-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 DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
You are given $n$ colored segments on the number line. Each segment is either colored red or blue. The $i$-th segment can be represented by a tuple $(c_i, l_i, r_i)$. The segment contains all the points in the range $[l_i, r_i]$, inclusive, and its color denoted by $c_i$:
if $c_i = 0$, it is a red segment;
if $c_i = 1$, it is a blue segment.
We say that two segments of different colors are connected, if they share at least one common point. Two segments belong to the same group, if they are either connected directly, or through a sequence of directly connected segments. Find the number of groups of segments.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of segments.
Each of the next $n$ lines contains three integers $c_i, l_i, r_i$ ($0 \leq c_i \leq 1, 0 \leq l_i \leq r_i \leq 10^9$), describing the $i$-th segment.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print a single integer $k$, the number of groups of segments.
-----Examples-----
Input
2
5
0 0 5
1 2 12
0 4 7
1 9 16
0 13 19
3
1 0 1
1 1 2
0 3 4
Output
2
3
-----Note-----
In the first example there are $5$ segments. The segments $1$ and $2$ are connected, because they are of different colors and share a point. Also, the segments $2$ and $3$ are connected, and so are segments $4$ and $5$. Thus, there are two groups: one containing segments $\{1, 2, 3\}$, and the other one containing segments $\{4, 5\}$. | from sys import stdin
def solve_case():
n = int(stdin.readline())
segs = [(tuple(map(int, stdin.readline().split())) + (i,)) for i in range(n)]
segs.sort(key=lambda x: x[1])
par = [-1] * n
cnt_comp = n
def find_set(u):
p = u
while par[p] >= 0:
p = par[p]
while u != p:
t = par[u]
par[u] = p
u = t
return p
def join(u, v):
nonlocal cnt_comp
nonlocal par
u = find_set(u)
v = find_set(v)
if u == v:
return
if -par[u] < -par[v]:
u, v = v, u
par[u] += par[v]
par[v] = u
cnt_comp -= 1
hp = [[], []]
for col, l, r, id in segs:
for elm in hp[1 - col]:
if elm[0] < l:
continue
join(elm[1], id)
if len(hp[1 - col]):
hp[1 - col] = [max(hp[1 - col])]
hp[col].append((r, id))
return cnt_comp
for testcase in range(int(stdin.readline())):
print(solve_case()) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR LIST LIST LIST FOR VAR VAR VAR VAR VAR FOR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR LIST FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given $n$ colored segments on the number line. Each segment is either colored red or blue. The $i$-th segment can be represented by a tuple $(c_i, l_i, r_i)$. The segment contains all the points in the range $[l_i, r_i]$, inclusive, and its color denoted by $c_i$:
if $c_i = 0$, it is a red segment;
if $c_i = 1$, it is a blue segment.
We say that two segments of different colors are connected, if they share at least one common point. Two segments belong to the same group, if they are either connected directly, or through a sequence of directly connected segments. Find the number of groups of segments.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of segments.
Each of the next $n$ lines contains three integers $c_i, l_i, r_i$ ($0 \leq c_i \leq 1, 0 \leq l_i \leq r_i \leq 10^9$), describing the $i$-th segment.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print a single integer $k$, the number of groups of segments.
-----Examples-----
Input
2
5
0 0 5
1 2 12
0 4 7
1 9 16
0 13 19
3
1 0 1
1 1 2
0 3 4
Output
2
3
-----Note-----
In the first example there are $5$ segments. The segments $1$ and $2$ are connected, because they are of different colors and share a point. Also, the segments $2$ and $3$ are connected, and so are segments $4$ and $5$. Thus, there are two groups: one containing segments $\{1, 2, 3\}$, and the other one containing segments $\{4, 5\}$. | t = int(input())
for _ in range(t):
n = int(input())
ends = []
for i in range(n):
c, l, r = map(int, input().split())
ends.append((l, 0, c, i))
ends.append((r, 1, c, i))
ends.sort()
groups = n
wait = [set(), set()]
combined = [0, 0]
totals = [0, 0]
for bound, is_closed, color, i in ends:
if not is_closed:
if totals[1 - color] == 0:
wait[color].add(i)
elif len(wait[1 - color]) > 0:
L = len(wait[1 - color])
groups -= combined[1 - color] > 0
combined[1 - color] += L
wait[1 - color] = set()
combined[color] += 1
groups -= L
else:
combined[color] += 1
groups -= 1
totals[color] += 1
else:
if i in wait[color]:
wait[color].remove(i)
else:
combined[color] -= 1
totals[color] -= 1
print(groups) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR VAR VAR VAR IF VAR IF VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
A.sort()
B = [A[0]]
move = 0
for a in A[1:]:
if a <= B[-1]:
step = B[-1] - a + 1
move += step
a = a + step
B.append(a)
return move | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
ans = 0
hp, hp2 = [], []
n, mina, maxa = len(A), min(A), max(A)
seen = set()
for a in A:
if a not in seen:
seen.add(a)
else:
heapq.heappush(hp, a)
for i in range(mina + 1, maxa + n):
if i not in seen:
heapq.heappush(hp2, i)
while hp:
while hp2[0] <= hp[0]:
heapq.heappop(hp2)
ans += heapq.heappop(hp2) - heapq.heappop(hp)
return ans | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
c = collections.Counter(A)
mv = 0
need = 0
for i in sorted(c):
mv += max(need - i, 0) * c[i] + c[i] * (c[i] - 1) // 2
need = max(need, i) + c[i]
return mv | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A):
bar = -1
res = 0
for a in sorted(A):
if a < bar:
res += bar - a
bar = max(bar + 1, a + 1)
return res | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
counter = collections.Counter(A)
taken = []
result = 0
for i in range(100000):
if counter[i] > 1:
taken.extend([i] * (counter[i] - 1))
elif taken and counter[i] == 0:
result += i - taken.pop()
return result | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
c = Counter(A)
print(c)
res = need = 0
for i in sorted(A):
res += max(need - i, 0)
need = max(need + 1, i + 1)
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
count = collections.Counter(A)
ans = 0
waiting = 0
for x in range(80000):
if count[x] >= 2:
waiting += count[x] - 1
ans -= x * (count[x] - 1)
elif waiting > 0 and count[x] == 0:
waiting -= 1
ans += x
return ans | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A.sort()
dup = []
seen = set()
for i in A:
if i not in seen:
seen.add(i)
else:
dup.append(i)
curr = 0
j = 0
i = -1
ans = 0
print(seen)
while j < len(dup):
if i == dup[j]:
curr = max(curr, i)
while curr in seen:
curr += 1
seen.add(curr)
ans += curr - dup[j]
j += 1
else:
i += 1
return ans | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
count = 0
A = sorted(A)
for i in range(len(A) - 1):
increment = max(0, A[i] - A[i + 1] + 1)
A[i + 1] += increment
count += increment
return count | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A.sort()
A.append(100000)
ans = taken = 0
for i in range(1, len(A)):
if A[i - 1] == A[i]:
taken += 1
ans -= A[i]
else:
give = min(taken, A[i] - A[i - 1] - 1)
ans += give * (give + 1) / 2 + give * A[i - 1]
taken -= give
return int(ans) | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A.sort()
A.append(100000)
result = taken = 0
for i in range(1, len(A)):
if A[i - 1] == A[i]:
taken += 1
result -= A[i]
else:
give = min(taken, A[i] - A[i - 1] - 1)
result += give * (give + 1) // 2 + give * A[i - 1]
taken -= give
return result
counter = collections.Counter(A)
taken = []
result = 0
for i in range(100000):
if counter[i] > 1:
taken.extend([i] * (counter[i] - 1))
elif taken and counter[i] == 0:
result += i - taken.pop()
return result | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if A == []:
return 0
else:
A.sort()
pre_item = A[0]
moves = 0
for i in range(1, len(A)):
cur_item = A[i]
if A[i] < pre_item or A[i] == pre_item:
moves = moves + pre_item + 1 - A[i]
A[i] = pre_item + 1
pre_item = A[i]
return moves | CLASS_DEF FUNC_DEF VAR VAR IF VAR LIST RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
ans = 0
c = Counter(A)
backlog = 0
for i in range(min(A), max(A) + 1):
if i in c:
backlog += c[i] - 1
elif i not in c and backlog:
ans += i
backlog -= 1
ans += sum(range(i + 1, i + 1 + backlog))
return sum(c.keys()) + ans - sum(A) | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
a = sorted(A)
res = 0
for i in range(0, len(a) - 1):
if a[i + 1] == a[i]:
a[i + 1] += 1
res += 1
elif a[i + 1] < a[i]:
k = a[i] - a[i + 1] + 1
a[i + 1] += k
res += k
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
count = collections.Counter(A)
taken = []
moves = 0
for i in range(45000):
c = count[i]
if c >= 2:
taken += (c - 1) * [i]
elif len(taken) > 0 and c == 0:
moves += i - taken.pop()
return moves | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER LIST VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
roots = {}
def find(k):
roots[k] = k if k not in roots else find(roots[k] + 1)
return roots[k]
return sum(find(a) - a for a in A) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
counts = Counter(A)
increments = 0
for num in range(100000):
count = counts[num]
if count > 1:
increments += count - 1
counts[num] = 1
if not counts[num + 1]:
counts[num + 1] = 0
counts[num + 1] += count - 1
return increments | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, arr: List[int]) -> int:
if not arr:
return 0
arr.sort()
s, ans = arr[0], 0
for i in arr:
ans += max(0, s - i)
s = max(s + 1, i + 1)
return ans | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
seen = set()
replicates = []
for i in A:
if i not in seen:
seen.add(i)
else:
replicates.append(i)
replicates.sort()
res = 0
next_candidates = 0
while replicates:
num = replicates.pop(0)
next_candidates = max(next_candidates, num)
while next_candidates in seen:
next_candidates += 1
seen.add(next_candidates)
res += next_candidates - num
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A):
A.sort()
ans = 0
for i in range(1, len(A)):
if A[i] > A[i - 1]:
continue
ans += A[i - 1] - A[i] + 1
A[i] = A[i - 1] + 1
return ans | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
A.sort()
i = 1
stack = []
current = A[0]
moves = 0
while i < len(A):
if A[i] == A[i - 1]:
stack.append(A[i])
elif len(stack) > 0:
for num in range(current + 1, A[i]):
moves += num - stack.pop()
if not stack:
break
current = A[i]
i += 1
while stack:
moves += current + 1 - stack.pop()
current += 1
return moves | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR FUNC_CALL VAR IF VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
a = sorted(A)
b = []
if a == sorted(set(a)):
return 0
res = 0
for i in range(0, len(a) - 1):
print("now: ", a[i], a[i + 1])
if a[i + 1] == a[i]:
a[i + 1] += 1
res += 1
elif a[i + 1] < a[i]:
k = a[i] - a[i + 1] + 1
a[i + 1] += k
res += k
print(b)
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
N, ans = 40000, 0
freq, free_slot = [0] * N, 0
for n in A:
freq[n] += 1
for i, r in enumerate(freq):
if r:
ans += r * (r - 1) // 2 + (free_slot - i) * r
free_slot += r
else:
free_slot = max(free_slot, i + 1)
return ans | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
step = 0
if not A or len(A) == 1:
return step
prev = float("-inf")
nums = sorted(A)
for e in nums:
if e <= prev:
step += prev - e + 1
prev += 1
else:
prev = e
return step | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
f = 80001 * [0]
max_ = -1
for i in A:
f[i] += 1
max_ = max(max_, i)
hold = []
res = 0
for i in range(max_ + len(A) + 1):
if hold and f[i] == 0:
res += i - hold.pop()
elif f[i] > 1:
hold = (f[i] - 1) * [i] + hold
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP NUMBER LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER LIST VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
min_num = min(A)
max_num = max(A)
count = collections.Counter(A)
taken = []
ans = 0
for x in range(100000):
if x > max_num and not taken:
break
if count[x] >= 2:
taken = taken + [x] * (count[x] - 1)
elif taken and count[x] == 0:
ans += x - taken.pop()
return ans | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
A.sort()
prev = A[0]
res = 0
for num in A[1:]:
if num <= prev:
prev += 1
res += prev - num
else:
prev = num
return res | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
counter = Counter(A)
to_place = []
min_key = float("inf")
for key in counter:
min_key = min(min_key, key)
if counter[key] > 1:
for i in range(counter[key] - 1):
to_place.append(key)
counter[key] = 1
i = min_key
moves = 0
to_place.sort(reverse=True)
while to_place:
if i not in counter and i > to_place[-1]:
moves += i - to_place.pop()
i += 1
return moves | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if len(A) == 0 or len(A) == 1:
return 0
A.sort()
cnt = 0
for i in range(1, len(A)):
if A[i - 1] >= A[i]:
temp = A[i]
A[i] = A[i - 1] + 1
cnt += A[i] - temp
return cnt | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A = sorted(A)
if not A:
return 0
k = A[0]
moves = 0
for i in range(1, len(A)):
if A[i] <= k:
moves += k + 1 - A[i]
A[i] = k + 1
k = A[i]
return moves | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if len(A) < 2:
return 0
A.sort()
N = len(A)
res = 0
start = 0
for i in range(1, N):
if A[i] - A[start] >= i - start:
start = i
else:
res += i - start - (A[i] - A[start])
return res | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
diff = 0
stack = []
c = Counter(A)
for i in range(min(c.keys()), max(c.keys()) + 1):
if i in c:
stack += [i] * (c[i] - 1)
elif i not in c and stack:
diff += i - stack.pop()
return diff + sum(range(i + 1, i + 1 + len(stack))) - sum(stack) | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
def find(x):
root[x] = find(root[x] + 1) if x in root else x
return root[x]
root = {}
return sum(find(i) - i for i in A) | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A.sort()
A_sum = sum(A)
cnt = 0
for i in range(1, len(A)):
if A[i] <= A[i - 1]:
cnt += A[i] - A[i - 1] + 1
A[i] = A[i - 1] + 1
return sum(A) - A_sum | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
n = {}
ans = 0
def find(j):
n[j] = find(n[j] + 1) if j in n else j
return n[j]
for i in A:
ans += find(i) - i
return ans | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A = sorted(A)
ans = 0
if len(A) == 0:
return 0
prev = A[0]
i = 1
while i < len(A):
if A[i] <= prev:
ans += prev - A[i] + 1
prev += 1
else:
prev = A[i]
i += 1
return ans | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
A.sort()
temp = A[0]
res = 0
for i in range(1, len(A)):
if A[i] > temp:
temp = A[i]
else:
res += temp + 1 - A[i]
temp += 1
return res | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
n = len(A)
if n < 2:
return 0
A.sort()
avails = deque()
for i in range(1, n):
if A[i] > A[i - 1] + 1:
avails.append([A[i - 1] + 1, A[i]])
if i == n - 1:
avails.append([A[i] + 1, A[i] + 2])
l, r = avails.popleft()
nexts = deque(range(l, r))
r = nexts.popleft()
pre = A[0]
res = 0
for i in range(1, n):
if A[i] == pre:
while r <= A[i]:
if nexts:
r = nexts.popleft()
elif avails:
l, r = avails.popleft()
nexts = deque(range(l, r))
r = nexts.popleft()
else:
r += 1
res += r - A[i]
A[i] = r
if nexts:
r = nexts.popleft()
elif avails:
l, r = avails.popleft()
nexts = deque(range(l, r))
r = nexts.popleft()
else:
r += 1
else:
pre = A[i]
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR WHILE VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A.sort()
ans = 0
for i in range(1, len(A)):
if i > 0 and A[i] <= A[i - 1]:
target = A[i - 1] + 1
ans += target - A[i]
A[i] = target
return ans | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A.sort()
ret = 0
for i in range(1, len(A)):
p = A[i - 1]
c = A[i]
if p >= c:
ret += p - c + 1
A[i] = p + 1
return ret | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
result = 0
A.sort()
for i in range(1, len(A)):
if A[i - 1] >= A[i]:
result += A[i - 1] - A[i] + 1
A[i] = A[i - 1] + 1
return result | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
A = sorted(A)
nums = set()
move = 0
prev = -1
for i in range(len(A)):
cur_num = A[i]
if cur_num <= prev:
cur_num = prev + 1
while cur_num in nums:
cur_num += 1
nums.add(cur_num)
move += cur_num - A[i]
prev = cur_num
return move | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
step = curr = 0
for e in sorted(A):
step += max(curr - e, 0)
curr = max(curr, e) + 1
return step | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
dic = dict(collections.Counter(A))
sortedDic = sorted(list(dic.items()), key=lambda x: x[0])
result = 0
while sortedDic:
num, freq = sortedDic.pop(0)
if freq > 1:
diff = freq - 1
if sortedDic and sortedDic[0][0] == num + 1:
sortedDic[0] = num + 1, diff + sortedDic[0][1]
else:
sortedDic.insert(0, (num + 1, diff))
result += diff
return result | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
A.sort()
results = 0
prev = None
for num in A:
if prev != None and num <= prev:
results += prev + 1 - num
prev = prev + 1
else:
prev = num
return results | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR NONE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
n = len(A)
A.sort()
tail_num = A[0]
result = 0
for i in range(1, n):
if A[i] > tail_num:
tail_num = A[i]
else:
tail_num += 1
result += tail_num - A[i]
return result | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if len(A) < 2:
return 0
A.sort()
ans, last = 0, A[0] - 1
for n in A:
if n > last:
last = n
else:
ans += last - n + 1
last += 1
return ans | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
n = len(A)
A.sort()
stack = []
ans = 0
A.append(A[-1] + n)
for i in range(1, n + 1):
if A[i] == A[i - 1]:
stack.append(A[i])
else:
for r in range(1, A[i] - A[i - 1]):
if stack:
ans += A[i - 1] + r - stack.pop()
else:
break
return ans | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A or len(A) == 1:
return 0
ans = 0
A.sort()
for i in range(1, len(A)):
if A[i - 1] >= A[i]:
gap = abs(A[i - 1] - A[i]) + 1
A[i] += gap
ans += gap
return ans | CLASS_DEF FUNC_DEF VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
if not A:
return 0
repeat = collections.deque()
A = sorted(A)
for i, v in enumerate(A):
if i and v == A[i - 1]:
repeat.append(v)
slots = sorted(list(set(list(range(A[0], A[-1] + 1))) - set(A)))
res = 0
for i in slots:
if repeat and i > repeat[0]:
res += i - repeat[0]
repeat.popleft()
return (
res
- sum(repeat)
+ sum([i for i in range(A[-1] + 1, A[-1] + 1 + len(repeat))])
) | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR |
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Β
Example 1:
Input: [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
Β
Note:
0 <= A.length <= 40000
0 <= A[i] < 40000 | class Solution:
def minIncrementForUnique(self, A: List[int]) -> int:
cnt = [(0) for i in range(80001)]
minv, ans, n = 40001, 0, len(A)
for i in A:
cnt[i] += 1
minv = min(minv, i)
for i in range(minv, 80001):
if not n:
break
if cnt[i] > 1:
cnt[i + 1] += cnt[i] - 1
ans += cnt[i] - 1
if cnt[i] == 1:
n -= 1
return ans | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | n = int(input())
num = list(map(int, input().split()))
s1 = n * (n - 1) // 2
su = sum(num)
s2 = su - s1
base = s2 // n
additional = s2 % n
out = []
for i in range(n):
val = base + i
if additional > 0:
additional -= 1
val += 1
out.append(str(val))
print(" ".join(out)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | n = int(input())
h = list(map(int, input().split()))
s = sum(h)
a = n * (n + 1) // 2
result = (s - a) // n
rest = (s - a) % n
print(*[(i + result + 1 if i <= rest else i + result) for i in range(1, n + 1)]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | n = int(input().strip())
a = [int(ai) for ai in input().strip().split()]
l = 1
r = max(a)
asum = sum(a)
ans = 0
while l <= r:
mid = l + r >> 1
if 2 * n * mid >= 2 * asum - n * n - n:
r = mid - 1
ans = mid
else:
l = mid + 1
asum = asum - (ans + ans + n - 1) * n // 2
for i in range(0, n):
a[i] = ans + int(asum > 0)
ans = ans + 1
asum = asum - 1
print(" ".join(str(ai) for ai in a)) | 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | N = int(input())
s = sum([int(a) for a in input().split()])
a = N * (N - 1) // 2
b = (s - a) % N
c = (s - a) // N
print(" ".join(map(str, [(i + c + 1 if i < b else i + c) for i in range(N)]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | n = int(input())
tot = sum(map(int, input().split()))
extra = n * (n - 1) // 2
smol = (tot - extra) // n
out = [(smol + i) for i in range(n)]
for i in range(tot - sum(out)):
out[i] += 1
print(" ".join(map(str, out))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
x = sum(l)
y = x // n - n // 2 - 2
while y * n + n * (n - 1) // 2 <= x:
y += 1
y -= 1
cut = x - (y * n + n * (n - 1) // 2)
ans = [(i + y + 1) for i in range(cut)]
ans += [(i + y + cut) for i in range(n - cut)]
print(" ".join(map(str, ans))) | IMPORT ASSIGN 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 VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | from sys import stdin, stdout
input = stdin.buffer.readline
print = stdout.write
def f(a, b):
return (a + b) * n // 2
n = int(input())
(*h,) = map(int, input().split())
s = sum(h)
l, r = 0, 10**12
while l < r:
m = l + r >> 1
if f(m, m + n - 1) < s:
l = m + 1
else:
r = m
l -= 1
y = f(l, l + n - 1)
for i in range(n):
print(f"{l + i + (i < s - y)} ") | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER 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 ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | import sys
n = int(input())
a = [int(v) for v in sys.stdin.readline().split()]
s = sum(a) - n * (n + 1) // 2
p = s // n
q = s % n
for j in range(n):
a[j] = j + 1 + p + (q > 0)
q = q - 1
print(" ".join(map(str, a))) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Omkar is standing at the foot of Celeste mountain. The summit is $n$ meters away from him, and he can see all of the mountains up to the summit, so for all $1 \leq j \leq n$ he knows that the height of the mountain at the point $j$ meters away from himself is $h_j$ meters. It turns out that for all $j$ satisfying $1 \leq j \leq n - 1$, $h_j < h_{j + 1}$ (meaning that heights are strictly increasing).
Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $h_j + 2 \leq h_{j + 1}$, then one square meter of dirt will slide from position $j + 1$ to position $j$, so that $h_{j + 1}$ is decreased by $1$ and $h_j$ is increased by $1$. These changes occur simultaneously, so for example, if $h_j + 2 \leq h_{j + 1}$ and $h_{j + 1} + 2 \leq h_{j + 2}$ for some $j$, then $h_j$ will be increased by $1$, $h_{j + 2}$ will be decreased by $1$, and $h_{j + 1}$ will be both increased and decreased by $1$, meaning that in effect $h_{j + 1}$ is unchanged during that minute.
The landslide ends when there is no $j$ such that $h_j + 2 \leq h_{j + 1}$. Help Omkar figure out what the values of $h_1, \dots, h_n$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.
Note that because of the large amount of input, it is recommended that your code uses fast IO.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^6$).
The second line contains $n$ integers $h_1, h_2, \dots, h_n$ satisfying $0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$Β β the heights.
-----Output-----
Output $n$ integers, where the $j$-th integer is the value of $h_j$ after the landslide has stopped.
-----Example-----
Input
4
2 6 7 8
Output
5 5 6 7
-----Note-----
Initially, the mountain has heights $2, 6, 7, 8$.
In the first minute, we have $2 + 2 \leq 6$, so $2$ increases to $3$ and $6$ decreases to $5$, leaving $3, 5, 7, 8$.
In the second minute, we have $3 + 2 \leq 5$ and $5 + 2 \leq 7$, so $3$ increases to $4$, $5$ is unchanged, and $7$ decreases to $6$, leaving $4, 5, 6, 8$.
In the third minute, we have $6 + 2 \leq 8$, so $6$ increases to $7$ and $8$ decreases to $7$, leaving $4, 5, 7, 7$.
In the fourth minute, we have $5 + 2 \leq 7$, so $5$ increases to $6$ and $7$ decreases to $6$, leaving $4, 6, 6, 7$.
In the fifth minute, we have $4 + 2 \leq 6$, so $4$ increases to $5$ and $6$ decreases to $5$, leaving $5, 5, 6, 7$.
In the sixth minute, nothing else can change so the landslide stops and our answer is $5, 5, 6, 7$. | import sys
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
k = (S - (N - 1) * (N - 2) // 2) % N
x = (S - (N - 1) * (N - 2) // 2 - k) // N
for i in range(N - 1):
sys.stdout.write(str(x + i) + " ")
if i == k:
sys.stdout.write(str(x + i) + " ")
if k == N - 1:
sys.stdout.write(str(x + k) + " ")
main() | IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN 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 VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | T = int(input())
deg = [(0) for i in range(110000)]
for t in range(T):
ans = 0
n = int(input())
w = input().split()
for i in range(n):
deg[i] = 0
w[i] = int(w[i])
ans += w[i]
for i in range(n - 1):
u, v = map(int, input().split())
deg[u - 1] += 1
deg[v - 1] += 1
wlist = []
for i in range(n):
for j in range(deg[i] - 1):
wlist.append(w[i])
wlist.sort(reverse=True)
print(ans, end=" ")
for i in wlist:
ans += i
print(ans, end=" ")
print("") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | t = int(input())
for i in range(t):
n = int(input())
w = list(map(int, input().split(" ")))
for i in range(len(w)):
w[i] = w[i], i + 1
deg = [(0) for i in range(n + 1)]
for i in range(n - 1):
u, v = map(int, input().split(" "))
deg[u] += 1
deg[v] += 1
w.sort()
s, c = 0, n - 1
for i in range(n):
s += w[i][0]
print(s, end=" ")
while c >= 0:
x, y = w[c][0], w[c][1]
if deg[y] == 1:
c -= 1
else:
s += x
deg[y] -= 1
print(s, 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 STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | for _ in range(int(input())):
n = int(input())
w = list(map(int, input().split()))
l = [-1] * n
for i in range(n - 1):
a, b = map(int, input().split())
l[a - 1] += 1
l[b - 1] += 1
ans = [sum(w)]
for i in range(n):
for j in range(l[i]):
ans.append(w[i])
ans.sort(reverse=True)
for i in range(1, len(ans)):
ans[i] += ans[i - 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | t = int(input())
while t:
t -= 1
n = int(input())
arr = list(map(int, input().split()[:n]))
req = [0] * n
for i in range(n - 1):
for v in input().split():
req[int(v) - 1] += 1
tmp = [0]
for i in range(n):
for j in range(req[i] - 1):
tmp.append(arr[i])
tmp.sort(reverse=1)
ans = [sum(arr)]
for i in range(n - 2):
ans.append(ans[-1] + tmp[i])
ans = [str(n) for n in ans]
print(" ".join(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 VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | import sys
readline = sys.stdin.readline
Q = int(readline())
Ans = [None] * Q
MOD = 10**9 + 7
for qu in range(Q):
N = int(readline())
W = list(map(int, readline().split()))
Edge = [[] for _ in range(N)]
Dim = [0] * N
for _ in range(N - 1):
a, b = map(int, readline().split())
a -= 1
b -= 1
Edge[a].append(b)
Edge[b].append(a)
Dim[a] += 1
Dim[b] += 1
ar = []
for i in range(N):
w = W[i]
ar.extend([w] * (Dim[i] - 1))
ar.sort(reverse=True)
ar = [sum(W)] + ar
for i in range(1, N - 1):
ar[i] += ar[i - 1]
Ans[qu] = " ".join(map(str, ar))
print("\n".join(Ans)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER 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 LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | def solve(t):
for _ in range(t):
N = int(input())
A = list(map(int, input().split()))
d = []
s = 0
for i in A:
d.append([i, 0])
s += i
for i in range(N - 1):
a, b = map(int, input().split())
d[a - 1][1] += 1
d[b - 1][1] += 1
d.sort(reverse=True)
a1 = [s]
p = 0
while p < N:
if d[p][1] > 1:
d[p][1] -= 1
s1 = a1[-1] + d[p][0]
a1.append(s1)
else:
p = p + 1
print(*a1)
t = int(input())
solve(t) | FUNC_DEF 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 LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
graph = dict()
for i in range(1, n + 1):
graph[i] = []
for i in range(n - 1):
x, y = map(int, input().split())
graph[x].append(y)
graph[y].append(x)
b = []
for i in graph:
if len(graph[i]) != 1:
for j in range(len(graph[i]) - 1):
b.append(a[i - 1])
b.sort(reverse=True)
s = sum(a)
print(s, end=" ")
for i in range(len(b)):
s += b[i]
print(s, 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | t = int(input())
while t:
t = t - 1
n = int(input())
l = list(map(int, input().split()))
d = [0] * n
for i in range(n - 1):
u, v = map(int, input().split())
d[u - 1] += 1
d[v - 1] += 1
ar = []
for i in range(n):
if len(ar) < n:
ar += [l[i]] * (d[i] - 1)
ar.sort(reverse=True)
an = [sum(l)]
for i in range(n - 2):
an.append(an[-1] + ar[i])
print(*an) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP LIST VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | t = int(input())
for _ in range(t):
n = int(input())
w = [int(x) for x in input().split()]
edges = []
seen = set()
for _ in range(n - 1):
u, v = map(int, input().split())
if u not in seen:
seen.add(u)
else:
edges.append(w[u - 1])
if v not in seen:
seen.add(v)
else:
edges.append(w[v - 1])
edges.sort(reverse=True)
answers = [sum(w)]
t = sum(w)
for i in edges:
t += i
answers.append(t)
print(*answers) | 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 LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | def func1(s, i, A, L):
for el in A:
if el not in s[max(i - 2, 0) : min(i + 3, L)]:
return el
t = int(input())
for _ in range(t):
n = int(input())
powers = [[int(el), 0] for el in input().split()]
for i in range(n - 1):
u, v = map(int, input().split())
powers[u - 1][1] += 1
powers[v - 1][1] += 1
ans = [(0) for i in range(n - 1)]
cnt = 0
for el in powers:
cnt += el[0] * el[1]
ans[n - 2] = cnt
y = n - 3
powers.sort()
x = 0
while y > -1:
while powers[x][1] == 1:
x += 1
powers[x][1] -= 1
cnt -= powers[x][0]
ans[y] = cnt
y -= 1
print(*ans) | FUNC_DEF FOR VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | import sys
lines = sys.stdin.readlines()
cur_line = -1
def input():
global lines, cur_line
cur_line += 1
return lines[cur_line][:-1]
for _ in range(int(input())):
n = int(input())
w = list(map(int, input().split()))
d = [(0) for _ in range(n)]
s = []
for _ in range(n - 1):
a, b = map(int, input().split())
d[a - 1] += 1
d[b - 1] += 1
for i in range(n):
s += [w[i]] * (d[i] - 1)
s.sort(reverse=True)
su = sum(w)
for i in range(n - 1):
print(su)
su += s[i] if i < len(s) else 0 | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER RETURN VAR VAR NUMBER 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP LIST VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | def buscaColoracao(ws, Q):
arestas = {}
for a, b in Q:
arestas[a] = arestas.get(a, 0) + 1
arestas[b] = arestas.get(b, 0) + 1
resultado = []
for k, v in arestas.items():
if v != 1:
ap = ws[k - 1]
for _ in range(v - 1):
resultado.append(ap)
base = sum(ws)
resultadoSort = sorted(resultado, reverse=True)
resultado = [base]
for ti in resultadoSort:
base += ti
resultado.append(base)
return resultado
t = int(input())
for _ in range(t):
n = int(input())
ws = list(map(int, input().split()))
grafo = []
for _ in range(n - 1):
u, v = map(int, input().split())
grafo.append((u, v))
print(" ".join(map(str, buscaColoracao(ws, grafo)))) | FUNC_DEF ASSIGN VAR DICT FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | t = int(input())
for _ in range(t):
n = int(input())
ls = list(map(int, input().split()))
end = [True] * n
count = [0] * n
bls = []
for _ in range(n - 1):
i, j = map(int, input().split())
count[i - 1] += 1
count[j - 1] += 1
if count[i - 1] > 1:
end[i - 1] = False
bls.append(ls[i - 1])
if count[j - 1] > 1:
end[j - 1] = False
bls.append(ls[j - 1])
s = sum(ls)
print(s, end=" ")
bls = sorted(bls, reverse=True)
for i in bls:
print(s + i, end=" ")
s += i
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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | def answer(n, A):
l = []
sum1 = 0
for i in A:
l.append([i, 0])
sum1 += i
for i in range(n - 1):
a, b = map(int, input().split())
l[a - 1][1] += 1
l[b - 1][1] += 1
l.sort(reverse=True)
ans = [sum1]
pointer = 0
while pointer < n:
if l[pointer][1] > 1:
l[pointer][1] -= 1
s = ans[-1] + l[pointer][0]
ans.append(s)
else:
pointer += 1
print(*ans)
t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split()))
answer(n, A) | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = []
d = dict()
for i in range(n - 1):
u, v = map(int, input().split())
if u in d:
d[u] += 1
else:
d[u] = 1
if v in d:
d[v] += 1
else:
d[v] = 1
for i in d:
if d[i] != 1:
for j in range(d[i] - 1):
b.append(a[i - 1])
b.sort(reverse=True)
s = sum(a)
j = 0
for i in range(n - 1):
print(s, end=" ")
if len(b) != 0:
s += b[j]
if j + 1 < len(b):
j += 1
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 LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | for _ in range(int(input())):
n = int(input())
maps = list(map(int, input().split()))
s = sum(maps)
row = []
dp = [0] * (n + 1)
for i in range(n - 1):
l, r = map(int, input().split())
l, r = l - 1, r - 1
dp[l] += 1
dp[r] += 1
if dp[l] > 1:
row += [maps[l]]
if dp[r] > 1:
row += [maps[r]]
row.sort(reverse=True)
result = [str(s)]
for i in row:
s += i
result += [str(s)]
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 VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR LIST VAR VAR IF VAR VAR NUMBER VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR LIST FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | def main():
t = int(input())
for i in range(t):
solve()
def solve():
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
counter = [[_, 0] for _ in a]
for i in range(n - 1):
u, v = map(int, input().split())
counter[u - 1][1] += 1
counter[v - 1][1] += 1
counter.sort(reverse=True, key=lambda x: x[0])
for i in range(len(counter) - 1, -1, -1):
if counter[i][1] <= 1:
counter.pop(i)
print(s, end=" ")
for i in range(n - 2):
s += counter[0][0]
counter[0][1] -= 1
if counter[0][1] <= 1:
counter.pop(0)
print(s, end=" ")
print()
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | for _ in range(int(input())):
n = int(input())
l = []
freq = [0] * n
wt = list(map(int, input().split()))
for i in range(n - 1):
x, y = map(int, input().split())
freq[x - 1] += 1
freq[y - 1] += 1
ans = []
for i in range(n):
if freq[i] >= 2:
ans.append([freq[i], wt[i]])
ans.sort(key=lambda x: x[-1], reverse=True)
j = 0
i = 0
s = sum(wt)
l.append(s)
while i < n - 2:
if ans[j][0] > 1:
s += ans[j][-1]
ans[j][0] -= 1
l.append(s)
if ans[j][0] == 1:
j += 1
i += 1
print(*l) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather than months to solve this task. But will you manage?
In this problem, you are given a tree with $n$ weighted vertices. A tree is a connected graph with $n - 1$ edges.
Let us define its $k$-coloring as an assignment of $k$ colors to the edges so that each edge has exactly one color assigned to it. Note that you don't have to use all $k$ colors.
A subgraph of color $x$ consists of these edges from the original tree, which are assigned color $x$, and only those vertices that are adjacent to at least one such edge. So there are no vertices of degree $0$ in such a subgraph.
The value of a connected component is the sum of weights of its vertices. Let us define the value of a subgraph as a maximum of values of its connected components. We will assume that the value of an empty subgraph equals $0$.
There is also a value of a $k$-coloring, which equals the sum of values of subgraphs of all $k$ colors. Given a tree, for each $k$ from $1$ to $n - 1$ calculate the maximal value of a $k$-coloring.
-----Input-----
In the first line of input, there is a single integer $t$ ($1 \leq t \leq 10^5$) denoting the number of test cases. Then $t$ test cases follow.
First line of each test case contains a single integer $n$ ($2 \leq n \leq 10^5$). The second line consists of $n$ integers $w_1, w_2, \dots, w_n$ ($0 \leq w_i \leq 10^9$), $w_i$ equals the weight of $i$-th vertex. In each of the following $n - 1$ lines, there are two integers $u$, $v$ ($1 \leq u,v \leq n$) describing an edge between vertices $u$ and $v$. It is guaranteed that these edges form a tree.
The sum of $n$ in all test cases will not exceed $2 \cdot 10^5$.
-----Output-----
For every test case, your program should print one line containing $n - 1$ integers separated with a single space. The $i$-th number in a line should be the maximal value of a $i$-coloring of the tree.
-----Examples-----
Input
4
4
3 5 4 6
2 1
3 1
4 3
2
21 32
2 1
6
20 13 17 13 13 11
2 1
3 1
4 1
5 1
6 1
4
10 6 6 6
1 2
2 3
4 1
Output
18 22 25
53
87 107 127 147 167
28 38 44
-----Note-----
The optimal $k$-colorings from the first test case are the following:
In the $1$-coloring all edges are given the same color. The subgraph of color $1$ contains all the edges and vertices from the original graph. Hence, its value equals $3 + 5 + 4 + 6 = 18$.
In an optimal $2$-coloring edges $(2, 1)$ and $(3,1)$ are assigned color $1$. Edge $(4, 3)$ is of color $2$. Hence the subgraph of color $1$ consists of a single connected component (vertices $1, 2, 3$) and its value equals $3 + 5 + 4 = 12$. The subgraph of color $2$ contains two vertices and one edge. Its value equals $4 + 6 = 10$.
In an optimal $3$-coloring all edges are assigned distinct colors. Hence subgraphs of each color consist of a single edge. They values are as follows: $3 + 4 = 7$, $4 + 6 = 10$, $3 + 5 = 8$. | def main():
n = int(input())
w = list(map(int, input().split()))
edge = [[] for _ in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
u -= 1
v -= 1
edge[u].append(v)
edge[v].append(u)
weights = []
for i in range(n):
if len(edge[i]) >= 2:
for _ in range(len(edge[i]) - 1):
weights.append(w[i])
weights.sort(reverse=True)
ans = [sum(w)]
for k in range(n - 1):
if k > 0:
ans.append(ans[-1] + weights[k - 1])
print(*ans)
return
t = int(input())
for i in range(t):
main() | 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 LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.