description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
a.append(list(map(int, input().split())))
for i in range(n):
b.append(list(map(int, input().split())))
d = []
for i in range(m + n - 1):
c = []
for j in range(n):
if 0 <= i - j < m:
c.append(a[j][i - j])
c.sort()
d.append(c)
e = []
for i in range(m + n - 1):
c = []
for j in range(n):
if 0 <= i - j < m:
c.append(b[j][i - j])
c.sort()
e.append(c)
f = 0
for i in range(len(d)):
if d[i] != e[i]:
f = 1
break
if f == 1:
print("NO")
else:
print("YES")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = [None] * n
for i in range(n):
a[i] = input().split()
b = [None] * n
for i in range(n):
b[i] = input().split()
flag = True
mi = min(m, n)
ma = max(m, n)
for i in range(mi):
da = {}
db = {}
ax = [a[j][i - j] for j in range(i + 1)]
bx = [b[j][i - j] for j in range(i + 1)]
for x in ax:
if x in da:
da[x] += 1
else:
da[x] = 1
for x in bx:
if x in db:
db[x] += 1
else:
db[x] = 1
if da != db:
flag = False
break
if flag:
for i in range(mi, mi + ma - 1):
da = {}
db = {}
if m > n:
ax = [a[j][i - j] for j in range(max(i + 1 - ma, 0), mi)]
bx = [b[j][i - j] for j in range(max(i + 1 - ma, 0), mi)]
else:
ax = [a[i - j][j] for j in range(max(i + 1 - ma, 0), mi)]
bx = [b[i - j][j] for j in range(max(i + 1 - ma, 0), mi)]
for x in ax:
if x in da:
da[x] += 1
else:
da[x] = 1
for x in bx:
if x in db:
db[x] += 1
else:
db[x] = 1
if da != db:
flag = False
break
if flag:
print("YES")
else:
print("NO")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = map(int, input().split())
a = []
for j in range(n):
te = [int(v) for v in input().split()]
a.append(te)
b = []
f = 0
for j in range(n):
te = [int(v) for v in input().split()]
b.append(te)
j = 0
while j < m:
k = 0
p = j
x = []
y = []
while k < n and p >= 0:
x.append(a[k][p])
y.append(b[k][p])
k = k + 1
p = p - 1
x.sort()
y.sort()
j = j + 1
if x[:] != y[:]:
f = 1
break
if f == 0:
j = 1
while j < n:
k = j
p = m - 1
x = []
y = []
while k < n and p >= 0:
x.append(a[k][p])
y.append(b[k][p])
k = k + 1
p = p - 1
x.sort()
y.sort()
j = j + 1
if x[:] != y[:]:
f = 1
break
if f == 0:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
def readLine():
a = input()
return [int(i) for i in a.split(" ")]
nm = readLine()
n, m = nm[0], nm[1]
a = [readLine() for _ in range(n)]
b = [readLine() for _ in range(n)]
ok = True
for i in range(n):
k, j = i, 0
l1, l2 = [], []
while k >= 0 and j < m:
l1.append(a[k][j])
l2.append(b[k][j])
k = k - 1
j = j + 1
l1.sort()
l2.sort()
for i, _ in enumerate(l1):
if l1[i] != l2[i]:
ok = False
for i in range(m):
k, j = n - 1, i
l1, l2 = [], []
while k >= 0 and j < m:
l1.append(a[k][j])
l2.append(b[k][j])
k = k - 1
j = j + 1
l1.sort()
l2.sort()
for i, _ in enumerate(l1):
if l1[i] != l2[i]:
ok = False
if ok:
print("YES")
else:
print("NO")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR LIST LIST WHILE VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR LIST LIST WHILE VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = tuple(map(int, input().strip().split()))
mat1 = []
for i in range(n):
mat1.append(list(map(int, input().strip().split())))
mat2 = []
for i in range(n):
mat2.append(list(map(int, input().strip().split())))
l = []
ll = []
for i in range(n + m - 1):
l.append([])
ll.append([])
for i in range(n):
for ii in range(m):
l[i + ii].append(mat1[i][ii])
ll[i + ii].append(mat2[i][ii])
for k in range(n + m - 1):
l[k].sort()
ll[k].sort()
q = 0
for t in range(n + m - 1):
for i in range(len(l[t])):
if l[t][i] != ll[t][i]:
print("NO")
q = 1
break
if q == 1:
break
if q == 0:
print("YES")
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = map(int, input().split())
a = []
b = []
f = 0
for i in range(n):
a.append(list(map(int, input().split())))
for i in range(n):
b.append(list(map(int, input().split())))
for i in range(n):
k = 0
ta = []
tb = []
while 1:
if i - k >= 0 and k < m:
ta.append(a[i - k][k])
tb.append(b[i - k][k])
else:
break
k += 1
ta.sort()
tb.sort()
for i in range(len(ta)):
if ta[i] != tb[i]:
f = 1
for j in range(m):
k = 0
ta = []
tb = []
while 1:
if j + k <= m - 1 and n - 1 - k >= 0:
ta.append(a[n - 1 - k][j + k])
tb.append(b[n - 1 - k][j + k])
else:
break
k += 1
ta.sort()
tb.sort()
for i in range(len(ta)):
if ta[i] != tb[i]:
f = 1
if f == 0:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = map(int, input().split())
a = [None] * n
b = [None] * n
f = [None] * (n + m)
g = [None] * (n + m)
for i in range(n + m):
f[i] = []
g[i] = []
for i in range(n):
a[i] = [int(o) for o in input().split()]
for j in range(m):
f[i + j].append(a[i][j])
for i in range(n):
b[i] = [int(o) for o in input().split()]
for j in range(m):
g[i + j].append(b[i][j])
flag = 0
for i in range(m + n):
f[i] = sorted(f[i])
g[i] = sorted(g[i])
if f[i] != g[i]:
flag = 1
break
if flag == 0:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR LIST ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = [int(s) for s in input().split()]
a = []
b = []
for i in range(n):
a.append([int(s) for s in input().split()])
for i in range(n):
b.append([int(s) for s in input().split()])
diagsa = []
diagsb = []
for i in range(n - 1):
k = i
j = 0
diagsa.append([])
diagsb.append([])
while j < m and k > -1:
diagsa[i].append(a[k][j])
diagsb[i].append(b[k][j])
j = j + 1
k = k - 1
diagsa[i].sort()
diagsb[i].sort()
for j in range(m):
k = j
i = n - 1
diagsa.append([])
diagsb.append([])
while k < m and i > -1:
diagsa[n - 1 + j].append(a[i][k])
diagsb[n - 1 + j].append(b[i][k])
i = i - 1
k = k + 1
diagsa[n - 1 + j].sort()
diagsb[n - 1 + j].sort()
for i in range(len(diagsa)):
if diagsa[i] != diagsb[i]:
print("NO")
break
else:
print("YES")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
l1, l2 = [[] for i in range(n + m)], [[] for i in range(n + m)]
for i in range(n):
for j in range(m):
l1[i + j].append(a[i][j])
l2[i + j].append(b[i][j])
for i in l1:
i.sort()
for i in l2:
i.sort()
print("YES" if l1 == l2 else "NO")
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR BIN_OP VAR VAR LIST VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
n, m = list(map(int, input().strip().split()))
a = []
b = []
for i in range(n):
l = list(map(int, input().strip().split()))
a.append(l)
for i in range(n):
l = list(map(int, input().strip().split()))
b.append(l)
test = True
for i in range(n + m - 1):
c = []
d = []
if i < m - 1:
for j in range(i, -1, -1):
c.append(a[i - j][j])
d.append(b[i - j][j])
if i - j == n - 1:
break
c.sort()
d.sort()
if c != d:
test = False
break
else:
x = i - (m - 1)
for j in range(x, n):
c.append(a[j][m - 1 - (j - x)])
d.append(b[j][m - 1 - (j - x)])
if m - 1 - (j - x) == 0:
break
c.sort()
d.sort()
if c != d:
test = False
break
if test == True:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
def func(maximum, list1, list2):
for i in range(maximum + 1):
list1[i].sort()
list2[i].sort()
if list1[i] != list2[i]:
return "NO"
return "YES"
n, m = map(int, input().split())
l = []
l1 = []
mm = m + n - 1
while len(l) < mm + 1:
l += [[]]
while len(l1) < mm + 1:
l1 += [[]]
for i in range(n):
temp = list(map(int, input().split()))
for j in range(m):
l[i + j] += [temp[j]]
for i in range(n):
temp = list(map(int, input().split()))
for j in range(m):
l1[i + j] += [temp[j]]
print(func(mm, l, l1))
|
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR LIST LIST WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.
Two matrices $A$ and $B$ are given, each of them has size $n \times m$. Nastya can perform the following operation to matrix $A$ unlimited number of times: take any square square submatrix of $A$ and transpose it (i.e. the element of the submatrix which was in the $i$-th row and $j$-th column of the submatrix will be in the $j$-th row and $i$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $A$).
Nastya's task is to check whether it is possible to transform the matrix $A$ to the matrix $B$.
$\left. \begin{array}{|c|c|c|c|c|c|c|c|} \hline 6 & {3} & {2} & {11} \\ \hline 5 & {9} & {4} & {2} \\ \hline 3 & {3} & {3} & {3} \\ \hline 4 & {8} & {2} & {2} \\ \hline 7 & {8} & {6} & {4} \\ \hline \end{array} \right.$ Example of the operation
As it may require a lot of operations, you are asked to answer this question for Nastya.
A square submatrix of matrix $M$ is a matrix which consist of all elements which comes from one of the rows with indeces $x, x+1, \dots, x+k-1$ of matrix $M$ and comes from one of the columns with indeces $y, y+1, \dots, y+k-1$ of matrix $M$. $k$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).
-----Input-----
The first line contains two integers $n$ and $m$ separated by space ($1 \leq n, m \leq 500$)Β β the numbers of rows and columns in $A$ and $B$ respectively.
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $A$ ($1 \leq A_{ij} \leq 10^{9}$).
Each of the next $n$ lines contains $m$ integers, the $j$-th number in the $i$-th of these lines denotes the $j$-th element of the $i$-th row of the matrix $B$ ($1 \leq B_{ij} \leq 10^{9}$).
-----Output-----
Print "YES" (without quotes) if it is possible to transform $A$ to $B$ and "NO" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
-----Examples-----
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
-----Note-----
Consider the third example. The matrix $A$ initially looks as follows.
$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$
Then we choose the whole matrix as transposed submatrix and it becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$
Then we transpose the submatrix with corners in cells $(2, 2)$ and $(3, 3)$.
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$
So matrix becomes
$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$
and it is $B$.
|
from sys import stdin, stdout
R, C = [int(x) for x in stdin.readline().split()]
mat1 = [([0] * C) for _ in range(R)]
mat2 = [([0] * C) for _ in range(R)]
for i in range(R):
mat1[i] = [int(x) for x in stdin.readline().split()]
for i in range(R):
mat2[i] = [int(x) for x in stdin.readline().split()]
for i in range(1, R + C):
if i <= C:
x = 0
y = i - 1
else:
x = i - C
y = C - 1
d1 = []
d2 = []
while x >= 0 and x < R and y >= 0 and y < C:
d1.append(mat1[x][y])
d2.append(mat2[x][y])
x += 1
y -= 1
d1.sort()
d2.sort()
for j in range(len(d1)):
if d1[j] != d2[j]:
print("NO")
quit()
print("YES")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
tc = int(input())
for _ in range(tc):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
chef = []
for i in range(n - 1, -1, -2):
chef.append(a[i])
print(sum(chef))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
T = int(input())
for j in range(T):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print(sum(a[::2]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
while t > 0:
n = int(input())
l = list(map(int, input().split()))
c = 0
l.sort()
l = l[::-1]
for i in range(0, len(l)):
if i % 2 == 0:
c = c + l[i]
else:
continue
print(c)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
while t:
n = int(input())
a = list(map(int, input().split()))
c = 0
a.sort(reverse=True)
for i in range(0, len(a), 2):
c += a[i]
print(c)
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 NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
def solve():
for _ in range(int(input())):
_ = int(input())
piles = list(map(int, input().split()))
print(sum(sorted(piles, reverse=True)[::2]))
solve()
|
FUNC_DEF 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 EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
for _ in range(t):
n = int(input())
s = list(map(int, input().split()))
s.sort(reverse=True)
cnt = 0
for i in range(0, n, 2):
cnt += s[i]
print(cnt)
|
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
N = int(input())
A = input().split()
for i in range(len(A)):
A[i] = int(A[i])
count = 0
A.sort()
for i in range(len(A) - 1, -1, -2):
count += A[i]
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = 0
while a:
try:
ans += max(a)
a.remove(max(a))
a.remove(max(a))
except:
break
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
l = arr[::-1]
x = l[::2]
print(sum(x))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
T = int(input())
for i in range(T):
N = int(input())
list = [int(x) for x in map(int, input().split())]
list.sort()
k = N - 1
sum = 0
while k >= 0:
sum = sum + list[k]
k = k - 2
print(sum)
|
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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
lis = list(map(int, input().split()))
lis.sort()
chef = sum([lis[i] for i in range(0, n, 2)])
other = sum(lis[i] for i in range(1, n, 2))
print(max(chef, other))
|
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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
a = sorted(map(int, input().split()))
r = 0
for i in range(n - 1, -1, -2):
r += a[i]
print(r)
|
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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
def merge(arr, low, mid, high):
n1 = mid - low + 1
n2 = high - mid
arr1 = []
arr2 = []
for i in range(n1):
arr1.append(arr[low + i])
for i in range(n2):
arr2.append(arr[mid + 1 + i])
k = low
i = 0
j = 0
while i < n1 and j < n2:
if arr1[i] < arr2[j]:
arr[k] = arr1[i]
k += 1
i += 1
else:
arr[k] = arr2[j]
k += 1
j += 1
while i < n1:
arr[k] = arr1[i]
k += 1
i += 1
while j < n2:
arr[k] = arr2[j]
k += 1
j += 1
return
def merge_sort(arr, low, high):
if low < high:
mid = (low + high) // 2
merge_sort(arr, low, mid)
merge_sort(arr, mid + 1, high)
merge(arr, low, mid, high)
return
t = int(input())
for z in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
merge_sort(arr, 0, n - 1)
total_sum = 0
for i in range(n - 1, -1, -2):
total_sum += arr[i]
print(total_sum)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
a = int(input(""))
for i in range(a):
x = int(input())
t = [int(x) for x in input().split()]
t.sort()
c = 0
if x % 2 != 0:
for j in range(0, len(t), 2):
c = c + t[j]
else:
for j in range(1, len(t), 2):
c = c + t[j]
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
n = int(input())
for i in range(n):
num = int(input())
arr = list(map(int, input().split()))
t = num // 2
k = num - t
arr.sort()
list1 = []
for i in range(num):
list1.append(arr[num - i - 1])
sum = 0
for i in range(0, num, 2):
sum = sum + list1[i]
print(sum)
|
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 VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
while t > 0:
n = int(input())
l = list(map(int, input().strip().split()))
l.sort(reverse=True)
maxi = 0
for i in range(n):
if i % 2 == 0:
maxi += l[i]
print(maxi)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if n < 3:
print(max(a))
else:
a.sort(reverse=True)
count = 0
for j in range(0, n, 2):
count += a[j]
print(count)
|
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 IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
for i in range(t):
ans = 0
n = int(input())
a = [int(x) for x in input().split()]
lis = sorted(a, reverse=True)
for val in range(0, len(lis), 2):
ans = ans + lis[val]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
l = [int(i) for i in input().split()]
g = sorted(l, reverse=True)
s = 0
for r in range(0, len(l), 2):
s += g[r]
print(s)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
for i in range(t):
a = []
n = int(input())
a = list(map(int, input().split()))
chef = []
roma = []
count = 0
a.sort(reverse=True)
for j in range(0, n, 2):
max1 = a[j]
chef.append(max1)
total = sum(chef)
print(total)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
q = int(input())
for i in range(q):
w = int(input())
e = str(input())
e = e + " "
r = ""
t = []
for i in e:
if i == " ":
t.append(int(r))
r = ""
else:
r = r + i
t.sort()
y = []
for i in range(len(t)):
y.append(t[len(t) - (i + 1)])
o = 0
for i in range(len(y)):
if i % 2 == 0:
o = o + y[i]
print(o)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for i in range(int(input())):
count = 0
n = int(input())
a = list(map(int, input().split(" ")))
a.sort()
count = 0
for j in range(len(a) - 1, -1, -2):
count = count + a[j]
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for i in range(int(input())):
n = int(input())
list1 = list(map(int, input().split()))
list1.sort(reverse=True)
j = 0
sum1 = 0
while j < n:
sum1 += list1[j]
j += 2
print(sum1)
|
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
print(
sum(
val if i % 2 == 0 else 0
for i, val in enumerate(
sorted(list(map(int, input().split())), reverse=True)
)
for k in range(1)
)
)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
for i in range(0, t):
n = int(input())
res = list(map(int, input().split()))
count = 0
res.sort()
for i in range(len(res) - 1, -1, -2):
count += res[i]
print(count)
|
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 NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
one, two = 0, 0
arr = sorted(arr, reverse=True)
for i in range(n):
if i & 1:
two += arr[i]
else:
one += arr[i]
print(max(one, two))
|
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 NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for i in range(int(input())):
noturn = int(input())
list1 = input().split()
list1 = sorted([int(i) for i in list1], reverse=True)
sum1 = 0
if noturn % 2 == 0:
for i in range(int(noturn / 2)):
sum1 += list1[i * 2]
else:
for i in range(int(noturn / 2) + 1):
sum1 += list1[i * 2]
print(sum1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
piles = sorted(list(map(int, input().split())))
print(sum([piles[i] for i in range(n - 1, -1, -2)]))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for i in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
s = 0
s1 = 0
for i in range(n):
if i % 2 == 0:
s = s + l[i]
else:
s1 = s1 + l[i]
print(s)
|
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
for i in range(t):
n = input()
a = sorted(map(int, input().split()), reverse=True)
sum = 0
i = 0
while i < len(a):
sum += a[i]
i += 2
print(sum)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
for _ in range(int(input())):
n = int(input())
c = 0
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(0, n, 2):
c += a[i]
print(c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
from sys import stdin
def main():
n = int(stdin.readline())
ls = [int(x) for x in stdin.readline().split()]
ls = sorted(ls, reverse=True)
s = 0
for i in range(0, n, 2):
s += ls[i]
print(s)
def __starting_point():
for _ in range(int(stdin.readline())):
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
for i in range(t):
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
o = 0
e = 0
if n % 2 == 0:
for i in range(len(l)):
if i % 2 != 0:
o = o + l[i]
print(o)
else:
for i in range(len(l)):
if i % 2 == 0:
e = e + l[i]
print(e)
|
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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of piles.
The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
-----Output-----
For each test case, output a single line containg the maximum number of stones that Chef can remove.
-----Constraints-----
- 1 β€ Ai β€ 109
- Subtask 1 (35 points): T = 10, 1 β€ N β€ 1000
- Subtask 2 (65 points): T = 10, 1 β€ N β€ 105
-----Example-----
Input:
2
3
1 2 3
3
1 2 1
Output:
4
3
|
t = int(input())
while t != 0:
t = t - 1
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
count = 0
for i in range(0, n, 2):
count += a[n - i - 1]
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
N, K = list(map(int, input().strip().split()))
monks = list(map(int, input().strip().split()))
def isPossible(mid, K):
i, j = 0, 0
prev = monks[0] + mid
K -= 1
for i in range(1, len(monks)):
if prev + mid >= monks[i]:
continue
if K == 0:
return False
prev = monks[i] + mid
K -= 1
return True
def lower_bound(left, right):
ans = 0
while right > left:
mid = left + (right - left) / 2
if isPossible(mid, K):
ans = mid
right = mid
else:
left = mid + 1
return ans
monks = sorted(monks)
print(lower_bound(0, 10000000))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def check(a, x, k):
prev_pos = x + a[0]
k -= 1
i = 1
while i < len(a):
next_pos = prev_pos + x
if a[i] <= next_pos:
i += 1
continue
prev_pos = a[i] + x
i += 1
k -= 1
return k >= 0
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
l = 0
r = 10**7
ans = 0
while l <= r:
mid = r - (r - l) / 2
if check(a, mid, k):
ans = mid
r = mid - 1
else:
l = mid + 1
print(ans)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def check(arr, mid, k):
nexta = arr[0] + mid
k -= 1
for i in range(1, len(arr)):
if nexta + mid < arr[i]:
if k == 0:
return False
k -= 1
nexta = arr[i] + mid
return True
n, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
l = 0
u = 10000000
mid = 0
while l <= u:
mid = (l + u) / 2
if check(A, mid, K):
if not check(A, mid - 1, K):
break
if check(A, mid, K):
u = mid - 1
else:
l = mid + 1
print(mid)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def is_enlightenment_possible(ar, n, k, dist):
pos = ar[0] + dist
for i in ar:
if abs(pos - i) > dist:
k = k - 1
pos = i + dist
k = k - 1
if k >= 0:
return True
return False
N, K = list(map(int, input().split()))
ar = list(map(int, input().split()))
ar.sort()
lo, hi = 1, 10000000
ans = 0
while lo <= hi:
mid = lo + hi >> 1
if is_enlightenment_possible(ar, N, K, mid):
ans = mid
hi = mid - 1
else:
lo = mid + 1
print(ans)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def is_enlightened(xs, k, power):
last_position = xs[0] + power
k -= 1
for x in xs:
if x > last_position + power:
last_position = x + power
k -= 1
return k >= 0
def solve(xs, k):
xs.sort()
start = 0
end = (xs[0] + xs[-1]) / 2 + 1
found = end
while start <= end:
mid = (start + end) / 2
if not is_enlightened(xs, k, mid):
start = mid + 1
else:
found = mid
end = mid - 1
return found
if __name__ == "__main__":
_, k = list(map(int, input().split()))
xs = list(map(int, input().split()))
print(solve(xs, k))
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
n, k = list(map(int, input().split()))
arr = sorted(map(int, input().split()))
lo, hi = 0, 10**7
while lo < hi:
mid = lo + (hi - lo) // 2
count, pos = 1, arr[0] + mid
for x in range(1, n):
if arr[x] - pos > mid:
count += 1
pos = arr[x] + mid
if count > k:
lo = mid + 1
else:
hi = mid
print(lo)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def possibleCheck(enlight, temples, n, k):
i = 0
m = 0
count = 0
while i < n and m < k:
pos = temples[i] + enlight
m += 1
i += 1
if i == n:
return True
while pos + enlight >= temples[i]:
i += 1
if i == n:
return True
return False
def enlightRange(minpos, maxpos, temples, n, k):
while minpos <= maxpos:
enlight = (minpos + maxpos) / 2
firstcheck = possibleCheck(enlight, temples, n, k)
scndcheck = possibleCheck(enlight - 1, temples, n, k)
if firstcheck and not scndcheck:
return enlight
elif firstcheck and scndcheck:
maxpos = enlight - 1
else:
minpos = enlight + 1
n, k = list(map(int, input().split()))
temples = list(map(int, input().split()))
temples.sort()
print(enlightRange(0, temples[n - 1], temples, n, k))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def check(t, nm, d):
m = t[0] + d
nm -= 1
for i in range(1, n):
if m + d >= t[i]:
continue
else:
if nm <= 0:
return 0
m = t[i] + d
nm -= 1
return 1
n, k = list(map(int, input().split()))
t = list(map(int, input().split()))
t.sort()
low, high, pos = 0, 10000000, -1
while low <= high:
mid = (low + high) / 2
if check(t, k, mid):
pos = mid
high = mid - 1
else:
low = mid + 1
print(pos)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
n, k = list(map(int, input().split(" ")))
pos = list(map(int, input().split(" ")))
pos.sort()
low = 0
high = 10000000
while low < high:
mid = low + high >> 1
possible = True
monkCount = 1
monk = pos[0] + mid
for p in range(1, n):
if pos[p] > monk + mid:
monk = pos[p] + mid
monkCount += 1
if monkCount > k:
possible = False
break
if possible:
high = mid
else:
low = mid + 1
print(high)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
Find the minimum enlightenment value such that all the temples can receive it.
Input Format:
The first line contains two integers, N and K - denoting the number of temples and number of monks. The next line contains N integers denoting the position of the temples in the straight line.
Output format:
Print the answer in a new line.
Constraints:
1 β€ N β€ 10^5
1 β€ K < N
1 β€ Positioni β€ 10^7
Update:
The enlightenment value is an integer.
SAMPLE INPUT
3 2
1 5 20
SAMPLE OUTPUT
2
Explanation
The optimal answer is 2.
A monk positioned at 3, can serve temples at 1 and 5.
The other monk can be placed at 18, to serve temple at 20.
|
def try_radius(temples, K, radius):
nbMonkRem = K
couv = -1
for temple in temples:
if temple <= couv:
continue
couv = temple + 2 * radius
nbMonkRem -= 1
if nbMonkRem == 0:
break
return temples[-1] <= couv
def binary_search_inversion(temples, K, x_min, x_max):
if x_min > x_max:
return 10**8
x = (x_min + x_max) / 2
if try_radius(temples, K, x):
r2 = binary_search_inversion(temples, K, x_min, x - 1)
return min(x, r2)
else:
return binary_search_inversion(temples, K, x + 1, x_max)
def solve(temples, K):
x_min = 0
x_max = (temples[-1] - temples[0]) / K // 2 + 1
return binary_search_inversion(temples, K, x_min, x_max)
_, K = list(map(int, input().split()))
temples = [int(v) for v in input().split()]
temples.sort()
print(solve(temples, K))
|
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER VAR FUNC_DEF IF VAR VAR RETURN BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Little Dima has two sequences of points with integer coordinates: sequence (a_1, 1), (a_2, 2), ..., (a_{n}, n) and sequence (b_1, 1), (b_2, 2), ..., (b_{n}, n).
Now Dima wants to count the number of distinct sequences of points of length 2Β·n that can be assembled from these sequences, such that the x-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.
Dima considers two assembled sequences (p_1, q_1), (p_2, q_2), ..., (p_{2Β·}n, q_{2Β·}n) and (x_1, y_1), (x_2, y_2), ..., (x_{2Β·}n, y_{2Β·}n) distinct, if there is such i (1 β€ i β€ 2Β·n), that (p_{i}, q_{i}) β (x_{i}, y_{i}).
As the answer can be rather large, print the remainder from dividing the answer by number m.
-----Input-----
The first line contains integer n (1 β€ n β€ 10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9). The third line contains n integers b_1, b_2, ..., b_{n} (1 β€ b_{i} β€ 10^9). The numbers in the lines are separated by spaces.
The last line contains integer m (2 β€ m β€ 10^9 + 7).
-----Output-----
In the single line print the remainder after dividing the answer to the problem by number m.
-----Examples-----
Input
1
1
2
7
Output
1
Input
2
1 2
2 3
11
Output
2
-----Note-----
In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2.
|
n = int(input())
c, d = {}, {}
for x, y in zip(input().split(), input().split()):
c[x] = c.get(x, 1) + 1
c[y] = c.get(y, 1) + 1
if x == y:
d[x] = d.get(x, 0) + 2
s, m = 1, int(input())
for k, v in c.items():
u = d.get(k, 0)
for i in range(v - u, v, 2):
s = s * (i * i + i) // 2 % m
for i in range(1, v - u):
s = s * i % m
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR DICT DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Little Dima has two sequences of points with integer coordinates: sequence (a_1, 1), (a_2, 2), ..., (a_{n}, n) and sequence (b_1, 1), (b_2, 2), ..., (b_{n}, n).
Now Dima wants to count the number of distinct sequences of points of length 2Β·n that can be assembled from these sequences, such that the x-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.
Dima considers two assembled sequences (p_1, q_1), (p_2, q_2), ..., (p_{2Β·}n, q_{2Β·}n) and (x_1, y_1), (x_2, y_2), ..., (x_{2Β·}n, y_{2Β·}n) distinct, if there is such i (1 β€ i β€ 2Β·n), that (p_{i}, q_{i}) β (x_{i}, y_{i}).
As the answer can be rather large, print the remainder from dividing the answer by number m.
-----Input-----
The first line contains integer n (1 β€ n β€ 10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9). The third line contains n integers b_1, b_2, ..., b_{n} (1 β€ b_{i} β€ 10^9). The numbers in the lines are separated by spaces.
The last line contains integer m (2 β€ m β€ 10^9 + 7).
-----Output-----
In the single line print the remainder after dividing the answer to the problem by number m.
-----Examples-----
Input
1
1
2
7
Output
1
Input
2
1 2
2 3
11
Output
2
-----Note-----
In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2.
|
n = int(input())
y = list(map(int, input().split()))
z = list(map(int, input().split()))
a = sorted([[y[i], i] for i in range(n)] + [[z[i], i] for i in range(n)])
f = 0
for i in range(n):
if y[i] == z[i]:
f += 1
m = int(input())
d = 0
e = 1
for i in range(1, 2 * n):
if a[i][0] != a[i - 1][0]:
for j in range(1, i - d + 1):
while f > 0 and j % 2 == 0:
j //= 2
f -= 1
e *= j
e %= m
d = i
for j in range(1, 2 * n - d + 1):
while f > 0 and j % 2 == 0:
j //= 2
f -= 1
e *= j
e %= m
print(e % m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR VAR FUNC_CALL VAR VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = int(1000000000.0 + 7)
def fact(x):
ans = 1
for i in range(2, x + 1):
ans = ans * i % mod
return ans
def C(x, k):
return (
fact(x)
* (pow(fact(k), mod - 2, mod) % mod)
* (pow(fact(x - k), mod - 2, mod) % mod)
)
def solve():
n, m = input().split()
n = int(n)
m = int(m)
arr = [0] * (n + 1)
for i in input().split():
x = int(i)
arr[x] += 1
for i in range(n, -1, -1):
if arr[i] >= m:
return int(C(arr[i], m) % mod)
else:
m -= arr[i]
return 1
no_tests = int(input())
results = []
for i in range(no_tests):
results.append(solve())
for result in results:
print(result)
|
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
from sys import stdin
fact = [1]
x = 1
for i in range(1, 1001):
x = x * i
fact.append(x)
input = stdin.buffer.readline
t = int(input())
for i in range(t):
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]
arr.sort()
p = n - k
cc = arr.count(arr[p])
cnt = 0
i = p
while i < n and arr[i] == arr[p]:
cnt = cnt + 1
i = i + 1
print(fact[cc] // (fact[cnt] * fact[cc - cnt]) % 1000000007)
|
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
input = sys.stdin.buffer.readline
mod = 10**9 + 7
def cmb(n, r):
if r < 0 or r > n:
return 0
return g1[n] * g2[r] * g2[n - r] % mod
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 10003):
g1.append(g1[-1] * i % mod)
inv.append(-inv[mod % i] * (mod // i) % mod)
g2.append(g2[-1] * inv[-1] % mod)
for t in range(int(input())):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
C = [0] * (N + 1)
for i in range(N):
C[A[i]] += 1
B = A[:K]
X = B[-1]
Y = B.count(X)
print(cmb(C[X], Y))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def factorial(number):
if number <= 1:
return 1
fact = 1
for i in range(1, number + 1):
fact *= i
return fact
def solution(array, k, n):
N = 0
R = 0
array.sort()
element = array[n - k]
for i in range(n - k, n):
if array[i] == element:
R += 1
for i in range(n):
if array[i] == element:
N += 1
answer = factorial(N) // (factorial(R) * factorial(N - R))
return answer % (1000000000 + 7)
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
array = list(map(int, input().split()))
ans = solution(array, k, n)
print(ans)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
input = sys.stdin.readline
t = int(input())
mod = 10**9 + 7
for tests in range(t):
n, k = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
x = A[k - 1]
count = 0
for a in A:
if a > x:
k -= 1
if a == x:
count += 1
ANS = 1
for i in range(k):
ANS = ANS * (count - i) * pow(i + 1, mod - 2, mod) % mod
print(ANS)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = 1000000007
t = int(input())
for i in range(t):
[n, k] = [int(k) for k in input().split()]
a = [int(k) for k in input().split()]
a.sort(reverse=True)
tot = 0
no = 0
for j in range(n):
if a[j] == a[k - 1]:
tot = tot + 1
if j < k:
no = no + 1
ans = 1
p = 1
for j in range(tot, tot - no, -1):
ans = ans * j
ans = ans // p
p = p + 1
print(ans % mod)
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def dell(lst, m):
dic = {}
for i in lst:
try:
dic[i] += 1
except:
dic[i] = 1
bok = list(dic.keys())
bok.sort(reverse=True)
sum = num = 0
for i in bok:
num = dic[i]
if sum + num >= m:
break
else:
sum += num
need = m - sum
b = a = 1
for i in range(num, num - need, -1):
b *= i
for i in range(1, need + 1):
a *= i
print(b // a % (10**9 + 7))
t = int(input())
for u in range(t):
l = input().split()
lst = list(map(int, input().split()))
dell(lst, int(l[1]))
|
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = 1000000007
fact = list()
fact.append(1)
for i in range(1, 1001):
fact.append(fact[len(fact) - 1] * i)
def C(n, k):
return fact[n] // fact[k] // fact[n - k]
def solve():
s = input().split()
n = int(s[0])
k = int(s[1]) - 1
a = list(map(int, input().split()))
a.sort(reverse=True)
i = k
j = k
while i > -1 and a[i] == a[k]:
i -= 1
while j < n and a[j] == a[k]:
j += 1
res = C(j - i - 1, k - i) % mod
print(res)
t = int(input())
while t:
solve()
t -= 1
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
fac = [(0) for i in range(1001)]
fac[0] = 1
mod = 10**9 + 7
for i in range(1, 1001):
fac[i] = fac[i - 1] * i % mod
for tt in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
mi = 1001
cnt = 0
for i in range(k):
if l[i] == mi:
cnt += 1
else:
cnt = 1
mi = min(mi, l[i])
cnt1 = cnt
for i in range(k, n):
if l[i] == mi:
cnt1 += 1
else:
break
print(
fac[cnt1]
* pow(fac[cnt], mod - 2, mod)
% mod
* pow(fac[cnt1 - cnt], mod - 2, mod)
% mod
)
|
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = num * (n - i) % p
den = den * (i + 1) % p
return num * pow(den, p - 2, p) % p
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
result = 1
if n > k:
d = {}
s = set()
for i in a:
if i not in d:
d[i] = 1
s.add(i)
else:
d[i] += 1
s = sorted(list(s))
s.reverse()
for i in s:
if k <= 0:
break
if d[i] <= k:
k -= d[i]
else:
n = d[i]
if 2 * k > n:
k = n - k
result = ncr(n, k, 10**9 + 7)
break
print(result)
|
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def binomial(n, k):
if not 0 <= k <= n:
return 0
b = 1
for t in range(min(k, n - k)):
b *= n
b //= t + 1
n -= 1
return b
for t in range(0, int(input())):
n, k = tuple(map(int, input().split()))
a = list(map(int, input().split()))
if k == 0:
print(0)
elif n == 1:
print(1)
else:
a = sorted(a, reverse=True)
i = 0
count = 0
nums = []
while count < k:
nums.append(a[i])
i += 1
count += 1
mn = min(nums)
x = nums.count(mn)
y = a.count(mn)
ans = binomial(y, x)
print(ans % (10**9 + 7))
|
FUNC_DEF IF NUMBER VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
from sys import stdin
nii = lambda: map(int, stdin.readline().split())
lnii = lambda: list(map(int, stdin.readline().split()))
t = int(input())
mod = 10**9 + 7
MAX_N = 10**3 + 5
fac = [1, 1] + [0] * MAX_N
finv = [1, 1] + [0] * MAX_N
inv = [0, 1] + [0] * MAX_N
for i in range(2, MAX_N):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def nCk(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
for tt in range(t):
n, k = nii()
a = lnii()
a.sort(reverse=True)
target = a[k - 1]
num = a[:k].count(target)
count = a.count(target)
ans = nCk(count, num) % mod
print(ans)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = num * (n - i) % p
den = den * (i + 1) % p
return num * pow(den, p - 2, p) % p
stdin = list(list(sys.stdin))
t = int(stdin[0].strip())
for i in range(t):
inp = stdin[2 * i + 1].rstrip().split(" ")
n = int(inp[0])
k = int(inp[1])
a = [int(i) for i in stdin[2 * i + 2].rstrip().split(" ")]
a.sort(reverse=True)
x = a[k - 1]
start = a.index(x)
print(ncr(a.count(x), k - start, 10**9 + 7))
|
IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def c2n(num, k):
k = min(k, num - k)
res = 1
nm = 1
dem = 1
while k > 0:
nm *= num
dem *= k
num -= 1
k -= 1
return nm // dem
t = int(input())
for _ in range(t):
n, m = [int(x) for x in input().split()]
lt = [int(x) for x in input().split()]
dt = {}
st = list(set(lt))
st = sorted(st, reverse=True)
for x in lt:
dt[x] = dt.get(x, 0) + 1
i = 0
ans = 1
while m > 0:
if dt[st[i]] <= m:
m -= dt[st[i]]
else:
ans = c2n(dt[st[i]], m)
m = 0
i += 1
print(ans % 1000000007)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
in_length = int(input())
final_ouput = []
for i in range(in_length):
[num_bloggers, av_contracts] = [int(el) for el in input().split()]
followers_p_b = [int(el) for el in input().split()]
followers_p_b = sorted(followers_p_b)
followers_p_b.reverse()
selected_bloggers = followers_p_b[:av_contracts]
lowest = selected_bloggers[-1]
n = followers_p_b.count(lowest)
r = selected_bloggers.count(lowest)
nr = n - r
m = 10**9 + 7
for j in range(1, n):
n = n * j
for k in range(1, r):
r = r * k
for l in range(1, nr):
nr = nr * l
if n == 0:
n = 1
if r == 0:
r = 1
if nr == 0:
nr = 1
ans = n // r // nr % m
final_ouput.append(ans)
for out in final_ouput:
print(out)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
f = [1] * 1001
fi = [1] * 1001
a = 1
m = 10**9 + 7
for i in range(1, 1001):
a *= i
a %= m
f[i] = a
b = pow(f[1000], m - 2, m)
fi[1000] = b
for i in range(999, 0, -1):
fi[i] = b * (i + 1) % m
b = fi[i]
for t in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
l1 = [0] * (n + 1)
for i in l:
l1[i] += 1
a = l.index(l[k - 1])
a = k - a
print(f[l1[l[k - 1]]] * fi[l1[l[k - 1]] - a] * fi[a] % m)
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda: list(map(int, sys.stdin.readline().rstrip("\r\n").split()))
mod = 10**9 + 7
Mod = 998244353
INF = float("inf")
def C(n, r, mod):
if r > n:
return 0
num = den = 1
for i in range(r):
num = num * (n - i) % mod
den = den * (i + 1) % mod
return num * pow(den, mod - 2, mod) % mod
tc = 1
(tc,) = inp()
for _ in range(tc):
n, k = inp()
a = inp()
a.sort(reverse=True)
b = a[:k]
a1 = b.count(b[-1])
a2 = a.count(b[-1])
print(C(a2, a1, mod))
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = 1000000000.0 + 7
c = [[(0) for i in range(1005)] for j in range(1005)]
c[0][0]
for i in range(1, 1001):
c[i][0] = c[i][i] = 1
for j in range(1, i):
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod
t = int(input())
while t:
t -= 1
n, k = map(int, input().split())
d = list(map(int, input().split()))
d.sort(reverse=True)
d.insert(0, 0)
p = 0
q = 0
for j in range(1, n + 1):
if d[j] == d[k]:
p += 1
for j in range(1, k + 1):
if d[j] == d[k]:
q += 1
print("%d" % c[p][q])
|
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
from sys import stdin
t = int(stdin.readline())
fact = [1]
for x in range(1, 1001):
fact.append(x * fact[-1])
def C(a, b):
return fact[b] // (fact[a] * fact[b - a]) % (10**9 + 7)
for _ in range(t):
n, k = map(int, stdin.readline().split())
arr = sorted(list(map(int, stdin.readline().split())), reverse=True)
dct = {}
minn = arr[k - 1]
position1 = 0
jump = n - 1
while jump > 0:
if position1 + jump >= n:
jump = jump // 2
elif arr[position1 + jump] <= minn:
jump = jump // 2
else:
position1 += jump
if arr[position1] > minn:
position1 += 1
position2 = 0
jump = n - 1
while jump > 0:
if position2 + jump >= n:
jump = jump // 2
elif arr[position2 + jump] < minn:
jump = jump // 2
else:
position2 += jump
print(C(k - 1 - position1 + 1, position2 - position1 + 1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
from sys import stdin
def modfac(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def modnCr(n, r, mod, fac, inv):
return fac[n] * inv[n - r] * inv[r] % mod
mod = 10**9 + 7
fac, inv = modfac(2000, mod)
tt = int(stdin.readline())
for loop in range(tt):
n, k = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
a.sort()
a.reverse()
x = a[k - 1]
cnt = 0
xnum = 0
for i in range(n):
if a[i] == x:
cnt += 1
if i < k:
xnum += 1
print(modnCr(cnt, xnum, mod, fac, inv) % mod)
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def aCb(a, b):
prod = 1
for f in range(a - b + 1, a + 1):
prod = prod * f
pro = 1
for j in range(1, b + 1):
pro = pro * j
return prod // pro
t = int(input())
for z in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
mf = []
for i in range(k):
mf.append(arr[i])
q = list(set(mf))
cou = 1
for num in q:
a = arr.count(num)
b = mf.count(num)
cou = cou * aCb(a, b)
cou = cou % 1000000007
print(cou)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
table = {}
def nCr(n, r):
if (n, r) in table:
return table[n, r]
elif r == 0:
return 1
elif r == 1:
return n
elif n == r:
return 1
else:
table[n, r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)) % 1000000007
return table[n, r]
def main():
T = int(input())
for c in range(T):
inp = input().rstrip().split(" ")
n, k = int(inp[0]), int(inp[1])
arr = input().rstrip().split(" ")
hmap = {}
for i in range(n):
if int(arr[i]) not in hmap:
hmap[int(arr[i])] = 0
hmap[int(arr[i])] += 1
arr = list(hmap.keys())
arr.sort(reverse=True)
m = 0
i = 0
while not m + hmap[arr[i]] >= k:
m += hmap[arr[i]]
i += 1
print(nCr(hmap[arr[i]], k - m))
main()
|
ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def combination(n, m):
a, b = 1, 1
for i in range(m + 1, n + 1):
a *= i
if b <= n - m and a % b == 0:
a //= b
b += 1
return a % (1000000000 + 7)
def agency():
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mp = {i: (0) for i in a}
b = a[n - m]
for i in a:
mp[i] += 1
k = 0
for i in range(n - m, n):
if a[i] != b:
break
k += 1
return combination(mp[b], k)
for i in range(int(input())):
print(agency())
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
MOD = 1000 * 1000 * 1000 + 7
fact = [1] * 1005
inv = [1] * 1005
def fastexp(base, exp):
if exp == 0:
return 1
temp = fastexp(base, exp // 2)
temp = temp * temp % MOD
if exp % 2 == 1:
temp = temp * base % MOD
return temp
def precompute():
for i in range(1, 1001):
fact[i] = fact[i - 1] * i % MOD
inv[i] = fastexp(fact[i], MOD - 2)
def choose(n, r):
return fact[n] * inv[r] % MOD * inv[n - r] % MOD
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
nchoose = 0
rchoose = 0
for i in range(n):
if a[i] == a[n - k]:
nchoose += 1
if i >= n - k:
rchoose += 1
print(choose(nchoose, rchoose))
def main():
precompute()
t = int(input())
for i in range(t):
solve()
main()
|
ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
from itertools import groupby, repeat
def line():
return map(int, input().split())
def num():
return int(input())
def nfunc(f, n, *args, **kwargs):
return (f(*args, **kwargs) for _ in repeat(None, n))
t = num()
for _ in repeat(None, t):
n, k = line()
blogs = [len(list(g)) for _, g in groupby(sorted(line())[::-1])]
ans = 1
for m in blogs:
if k <= m:
for i in range(1, k + 1):
ans *= m - k + i
for i in range(1, k + 1):
ans //= i
break
else:
k -= m
print(ans % (10**9 + 7))
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NONE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NONE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
mod = int(1000000000.0 + 7)
inv = [0] * int(10000.0)
def precalc(upper_bound, m=mod):
upper_bound = int(upper_bound)
inv[1] = 1
for i in range(2, upper_bound):
inv[i] = m - m // i * inv[m % i] % m
def choose(n, r, m=mod):
n = int(n)
r = int(r)
m = int(m)
if r == 1:
return n % m
res = 1
for i in range(0, r):
res *= (n - i) % m * inv[i + 1] % m
return res % m
T = int(input())
precalc(1000.0 + 10)
while T:
m = list(map(int, input().split(" ")))
n, k = int(m[0]), int(m[1])
a = list()
a = list(map(int, input().split(" ")))
freq = [0] * 1010
for i in range(n):
freq[a[i]] += 1
a.sort(reverse=True)
ans = 1
last = a[k - 1]
ch = k
for i in range(k):
ch -= 1
if a[i] == last:
ans = choose(freq[a[i]], ch + 1)
break
print(int(ans))
T -= 1
|
IMPORT ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = int(1000000000.0 + 7)
def fact(n):
ans = 1
for i in range(2, n + 1):
ans = ans * i
return ans
def comb(n, k):
ans = fact(n)
ans //= fact(k) * fact(n - k)
return ans % mod
for insjdfsdf in range(int(input())):
n, k = map(int, input().split())
L = list(map(int, input().split()))
us = [(0) for i in range(n + 1)]
for i in range(n):
us[L[i]] += 1
L.sort(reverse=True)
ans = 1
least = L[k - 1]
for i in range(k):
x = L[i]
if x == least:
T = comb(us[x], k - i)
ans = ans * T
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
fact = [1]
for i in range(1, 1002):
fact.append(fact[i - 1] * i)
def comb(n, k):
return fact[n] // (fact[n - k] * fact[k])
for t in range(int(input())):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
store = {}
for i in a:
if i in store:
store[i] += 1
else:
store[i] = 1
a = sorted(list(set(a)))
count = 0
for i in a[::-1]:
if count + store[i] >= k:
ans = comb(store[i], k - count)
break
count += store[i]
print(ans % (10**9 + 7))
|
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def modPower(x, y):
M = 10**9 + 7
res = 1
while y:
if y % 2 == 1:
res = res * x % M
x = x * x % M
y = y // 2
return res
M = 10**9 + 7
fact = [0] * 1001
rfact = [0] * 1001
fact[0] = 1
rfact[0] = 1
for i in range(1, 1001):
fact[i] = fact[i - 1] * i % M
rfact[i] = modPower(fact[i], M - 2)
for _ in range(int(input())):
n, k = map(int, input().split())
ll = list(map(int, input().split()))
ll.sort()
req = ll[n - k]
a = 0
for i in range(n):
if ll[i] == req:
a += 1
b = 0
for i in range(n - k, n):
if ll[i] == req:
b += 1
ans = fact[a] % M * rfact[b] % M % M
print(ans * rfact[a - b] % M)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def cnk_mod(max_n, m):
cnk = [[1]]
for n in range(1, max_n + 1):
tmp = [1]
for k in range(1, n):
tmp.append((cnk[n - 1][k - 1] + cnk[n - 1][k]) % m)
tmp.append(1)
cnk.append(tmp)
return cnk
M = 10**9 + 7
cnk = cnk_mod(1001, M)
tests = int(input())
for t in range(tests):
n, k = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
a.sort()
x = 0
i = n - k - 1
while i >= 0 and a[i] == a[n - k]:
x += 1
i -= 1
y = 0
i = n - k
while i < n and a[i] == a[n - k]:
y += 1
i += 1
print(cnk[x + y][x])
|
FUNC_DEF ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
MOD = 10**9 + 7
def factorial(n):
ans = 1
for i in range(2, n + 1):
ans = ans * i % MOD
return ans
def C(n, k):
nn = factorial(n)
kk = 1
for i in range(2, k + 1):
kk = kk * pow(i, MOD - 2, MOD) % MOD
nk = 1
for i in range(2, n - k + 1):
nk = nk * pow(i, MOD - 2, MOD) % MOD
return nn * kk * nk % MOD
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt1 = 0
cnt2 = 0
for i in range(0, k):
if a[i] == a[k - 1]:
cnt1 += 1
for i in range(k, n):
if a[i] == a[k - 1]:
cnt2 += 1
print(C(cnt1 + cnt2, cnt2))
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
fact = [1] * 1001
for i in range(1, 1001):
fact[i] = fact[i - 1] * i
MOD = 10**9 + 7
def solve():
n, k = map(int, input().split())
a = [int(s) for s in input().split()]
a.sort(reverse=True)
cnt = [0] * (n + 1)
for i in a:
cnt[i] += 1
used = [0] * (n + 1)
for i in range(k):
used[a[i]] += 1
id = -1
for i in range(n + 1):
if used[i] == 0 or used[i] == cnt[i]:
continue
if used[i] != cnt[i] and id == -1:
id = i
elif used[i] != cnt[i] and id != -1:
exit(1)
ans = 1
if id != -1:
N = cnt[id]
K = used[id]
ans *= fact[N] // (fact[K] * fact[N - K])
ans %= MOD
print(ans)
def main():
for i in range(int(input())):
solve()
main()
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = 10**9 + 7
def choose(n, r):
x = 1
for i in range(n - r + 1, n + 1):
x *= i
for i in range(1, r + 1):
x //= i
return x % mod
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
s = sum(arr[0:k])
freq = [0] * (n + 1)
for i in range(n):
freq[arr[i]] += 1
i = n
while k >= freq[i]:
k -= freq[i]
i -= 1
print(choose(freq[i], k))
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
input = sys.stdin.readline
def make_nCr_mod(max_n=2 * 10**5, mod=10**9 + 7):
max_n = min(max_n, mod - 1)
fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)
fact[0] = 1
for i in range(max_n):
fact[i + 1] = fact[i] * (i + 1) % mod
inv_fact[-1] = pow(fact[-1], mod - 2, mod)
for i in reversed(range(max_n)):
inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod
def nCr_mod(n, r):
res = 1
while n or r:
a, b = n % mod, r % mod
if a < b:
return 0
res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
n //= mod
r //= mod
return res
return nCr_mod
nCk = make_nCr_mod(1000, mod=10**9 + 7)
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
smallest = a[k - 1]
left = 0
i = k - 2
while i >= 0 and a[i] == smallest:
i -= 1
left += 1
right = 0
i = k
while i < n and a[i] == smallest:
i += 1
right += 1
print(nCk(left + right + 1, left + 1))
|
IMPORT ASSIGN VAR VAR FUNC_DEF BIN_OP NUMBER BIN_OP NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
input = sys.stdin.readline
getint = lambda: int(input())
getints = lambda: [int(a) for a in input().split()]
def solve():
n, k = getints()
a = getints()
mod = 1000000007
counts = [(0) for i in range(n + 1)]
for v in a:
counts[v] += 1
res = 1
pool = 0
for count in reversed(counts):
if k > count:
k -= count
else:
pool = count
break
if k >= pool // 2:
k = pool - k
for i in range(k):
res = res * (pool - i) // (1 + i)
print(res % mod)
t = getint()
for i in range(t):
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
def getn(a, b):
ans = 1
div = 1
for i in range(0, b):
ans *= a - i
for i in range(1, b + 1):
div *= i
ans //= div
return ans % 1000000007
tot = int(input())
for i in range(0, tot):
mp = list(input().split())
n = int(mp[0])
k = int(mp[1])
mp = list(input().split())
lst = list()
dct = dict()
for i in mp:
t = int(i)
if dct.get(t, 0) > 0:
dct[t] += 1
else:
dct[t] = 1
lst.append(t)
lst.sort()
i = 0
ans = 1
while i < k:
t = lst.pop()
dt = dct[t]
gets = min(dt, k - i)
ans *= getn(dt, gets)
ans %= 1000000007
i += gets
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
t = int(input())
def nCr(n, r):
return fact(n) // (fact(r) * fact(n - r))
def fact(n):
res = 1
for i in range(2, n + 1):
res = res * i
return res
for _ in range(t):
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p, reverse=True)
d = {}
for i in p:
if i in d:
d[i] += 1
else:
d[i] = 1
x = p[:k]
x.reverse()
t = x[0]
i = 0
while i < len(x) and x[i] == t:
i += 1
print(int(nCr(d[t], i)) % 1000000007)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = 10**9 + 7
def ncr(a, b):
c = 1
for i in range(a, b, -1):
c = c * i % mod
d = 1
for i in range(1, a - b + 1):
d = d * i % mod
d = pow(d, mod - 2, mod)
return c * d % mod
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
d = {}
for i in range(k):
try:
d[l[i]] += 1
except:
d[l[i]] = 1
e = {}
for i in l:
try:
e[i] += 1
except:
e[i] = 1
ans = 1
for i in d:
ans = ans * ncr(e[i], d[i])
print(ans)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
import sys
input = sys.stdin.readline
M = 10**9 + 7
def inv(n):
return power(n, M - 2)
def power(x, y):
ans = 1
while y > 0:
if y % 2 == 1:
ans = ans * x % M
y = y // 2
x = x * x % M
return ans % M
def com(n, r):
if r == 0:
return 1
else:
return f[n] * inv(f[n - r]) % M * inv(f[r]) % M % M
f = [1]
x = 1
for i in range(1, 10**5 + 3):
x = x * i % M
f.append(x)
for _ in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = n - 1
cnt = 0
p = {}
while cnt != k:
x = l[i]
if x in p:
p[x] += 1
else:
p[x] = 1
cnt += 1
i -= 1
d = {}
for i in l:
if i in d:
d[i] += 1
else:
d[i] = 1
ans = 1
for i in p:
r = p[i]
n = d[i]
ans = ans * com(n, r) % M
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.
Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.
Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).
For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:
conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.
conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.
Since the answer can be quite large, output it modulo $10^9+7$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 1000$) β the number of test cases. Then $t$ test cases follow.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) β the number of bloggers and how many of them you can sign a contract with.
The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) β the number of followers of each blogger.
It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.
-----Output-----
For each test case, on a separate line output one integer β the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.
-----Examples-----
Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1
-----Note-----
The test case is explained in the statements.
In the second test case, the following ways are valid:
conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;
conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;
conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;
conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;
conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;
conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.
In the third test case, the following ways are valid:
concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.
|
mod = 10**9 + 7
def calc(n, r):
return fact[n] * pow(fact[r] * fact[n - r] % mod, mod - 2, mod) % mod
fact = [1, 1]
for i in range(2, 10000):
fact.append(fact[-1] * i % mod)
for nt in range(int(input())):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
num = a[k - 1]
for i in range(n):
if a[i] == num:
count = i
break
print(calc(a.count(num), k - count))
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
q = int(input())
for i in range(q):
n = int(input())
arr = [(0) for i in range(n)]
for i in range(n):
temp = list(map(int, input().split()))
temp.append(i)
arr[i] = temp
arr = sorted(arr, key=lambda l: l[0])
ans = [(1) for i in range(n)]
yoyo = -1
maxa = arr[0][1]
for i in range(1, n):
if arr[i][0] > maxa:
yoyo = i
break
if arr[i][1] > maxa:
maxa = arr[i][1]
if yoyo == -1:
print(-1)
continue
else:
for i in range(yoyo, n):
ans[arr[i][2]] = 2
for i in range(n):
print(ans[i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing process you will be given multitest.
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 50000$) β the number of queries. Each query contains description of the set of segments. Queries are independent.
First line of each query contains single integer $n$ ($2 \le n \le 10^5$) β number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.
The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) β the $i$-th segment.
-----Output-----
For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) β for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.
If there are multiple answers, you can print any of them. If there is no answer, print $-1$.
-----Example-----
Input
3
2
5 5
2 3
3
3 5
2 3
2 3
3
3 3
4 4
5 5
Output
2 1
-1
1 1 2
-----Note-----
In the first query the first and the second segments should be in different groups, but exact numbers don't matter.
In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.
In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.
|
t = int(input())
for _ in range(t):
n = int(input())
x = []
for i in range(n):
l, r = map(int, input().split())
x.append((l, r, i))
x.sort()
e = x[0][0]
g = ["2"] * n
done = False
res = ""
for y in x:
if e < y[0]:
done = True
break
e = max(e, y[1])
g[y[2]] = "1"
if not done:
print(-1)
else:
print(" ".join(g))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.