description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
for i in range(n):
if a[i] in d.keys():
d[a[i]] = min([d[a[i]], b[i]])
else:
d[a[i]] = b[i]
if len(d.keys()) < k:
print(-1)
continue
outs = sorted([i for i in d.values()])
print(sum(outs[:k]))
|
FOR VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for i in range(t):
n, k = list(map(int, input().split()))
category = list(map(int, input().split()))
food_time = list(map(int, input().split()))
food = {}
for j in range(n):
if category[j] in food:
Previous_time = food[category[j]]
if Previous_time > food_time[j]:
food[category[j]] = food_time[j]
else:
food[category[j]] = food_time[j]
if len(food) >= k:
min_time = sorted(list(food.values()))
print(sum(min_time[0:k]))
else:
print("-1")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
res = {}
for i in range(n):
if res.get(a[i], -1) == -1:
res[a[i]] = b[i]
else:
res[a[i]] = min(res.get(a[i], 0), b[i])
l = len(res)
if k > l:
print(-1)
else:
ans = sum(list(sorted(res.values())[:k]))
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for i in range(int(input())):
Num, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dt = {}
if len(set(A)) < K:
print(-1)
else:
for i in range(len(A)):
if A[i] not in dt:
dt[A[i]] = B[i]
elif dt[A[i]] > B[i]:
dt[A[i]] = B[i]
lis = list(dt.values())
lis.sort()
Sum = sum(lis[0:K])
print(Sum)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
if a[i] in d:
d[a[i]] = min(d[a[i]], b[i])
else:
d[a[i]] = b[i]
li = []
for i in d:
li.append((i, d[i]))
if len(li) >= k:
li.sort(key=lambda x: x[1])
ans = 0
for i in range(k):
ans += li[i][1]
print(ans)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
def dinner(n, k, a, b):
d = {}
for i in range(n):
if a[i] in d:
d[a[i]].append(b[i])
else:
d[a[i]] = [b[i]]
c = set(a)
if len(c) < k:
return -1
else:
s = 0
exi = []
for i in d:
mini = min(d[i])
exi.append(mini)
exi.sort()
return sum(exi[:k])
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = dinner(n, k, a, b)
print(ans)
|
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
if a[i] not in d:
d[a[i]] = b[i]
else:
d[a[i]] = min(d[a[i]], b[i])
l = list(d.values())
l = sorted(l)
if len(l) >= k:
y = l[:k]
x = sum(y)
print(x)
else:
print(-1)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
def dinner(category, time, N, K):
look = list(zip(time, category))
look.sort()
distinct = {}
ans = 0
for i in range(N):
if len(distinct) >= K:
return ans
if look[i][1] in distinct:
continue
else:
distinct[look[i][1]] = True
ans += look[i][0]
if len(distinct) >= K:
return ans
return -1
for i in range(int(input())):
N, K = map(int, input().split())
category = list(map(int, input().split()))
time = list(map(int, input().split()))
print(dinner(category, time, N, K))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for t in range(t):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = {}
for i in range(n):
if a[i] not in ans:
ans[a[i]] = b[i]
elif ans[a[i]] > b[i]:
ans[a[i]] = b[i]
if len(ans) < k:
print(-1)
else:
arr = sorted(ans.values())
s = len(arr) - k
for i in range(s):
arr.remove(arr[len(arr) - 1])
time = sum(arr)
print(time)
|
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
d = {}
for i in range(len(l1)):
if l1[i] not in d:
d[l1[i]] = l2[i]
elif l2[i] < d[l1[i]]:
d[l1[i]] = l2[i]
if len(list(d.keys())) < k:
print(-1)
else:
lst = list(d.values())
c = 0
t = 0
lst = sorted(lst)
for i in range(k):
t += lst[i]
print(t)
|
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
testcases = int(input())
for _ in range(testcases):
smallest = []
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
d = dict.fromkeys(l2)
for j in l2:
d[j] = list()
for i in range(l1[0]):
d[l2[i]].append(l3[i])
for i in d.keys():
d[i] = sorted(d[i])
for i in d.values():
smallest.append(i[0])
if len(d.keys()) < l1[1]:
print(-1)
else:
print(sum(sorted(smallest)[: l1[1]]))
|
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
n = int(input())
for i in range(n):
l, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = dict()
for i in range(l):
try:
aa[a[i]] = min(aa[a[i]], b[i])
except:
aa[a[i]] = b[i]
if len(aa) < k:
print(-1)
continue
aa1 = sorted(aa.items(), key=lambda x: x[1])
an = 0
for i in aa1:
an += i[1]
k -= 1
if k == 0:
break
print(an)
|
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dic = {}
temp = max(b)
for j in a:
dic[j] = temp
for j in range(n):
dic[a[j]] = min(dic[a[j]], b[j])
if len(dic) < k:
print(-1)
else:
l = [j for j in dic.values()]
l.sort()
ans = 0
for j in range(len(l)):
if j >= k:
break
ans += l[j]
print(ans)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
lsta = list(map(int, input().split()))
lstc = []
lstb = list(map(int, input().split()))
dict = {}
for i in range(n):
if lsta[i] in dict:
dict[lsta[i]] = min(lstb[i], dict[lsta[i]])
else:
dict[lsta[i]] = lstb[i]
for key, value in dict.items():
lstc.append(value)
lstc.sort()
ans = 0
if k <= len(lstc):
for i in range(k):
ans += lstc[i]
if len(lstc) < k:
print(-1)
else:
print(ans)
|
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 LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
while t > 0:
n, k = map(int, input().split())
c = list(map(int, input().split()))
time = list(map(int, input().split()))
d = {}
for i in range(n):
if c[i] not in d.keys():
d[c[i]] = time[i]
else:
d[c[i]] = min(d[c[i]], time[i])
if len(d) < k:
print(-1)
else:
l = list(d.values())
l.sort()
print(sum(l[:k]))
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
def solve():
n, k = map(int, input().split())
di = dict()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
if a[i] in di:
di[a[i]] = min(b[i], di[a[i]])
else:
di[a[i]] = b[i]
val = list(di.values())
print(sum(sorted(val)[:k]) if len(val) >= k else -1)
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
if len(set(a)) < k:
print(-1)
continue
for i in range(len(a)):
d[a[i]] = b[i]
for i in range(len(a)):
d[a[i]] = min(b[i], d[a[i]])
c = 0
l = 0
for i in sorted(d.values()):
if l < k:
c += i
l += 1
print(c)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for i in range(t):
n_k = input().split(" ")
category = input().split(" ")
time = input().split(" ")
s_cat = set(category)
if len(s_cat) < int(n_k[1]):
print(-1)
else:
l_time = {}
for j in range(int(n_k[0])):
if category[j] not in l_time:
l_time.update({category[j]: int(time[j])})
elif category[j] in l_time and l_time.get(category[j]) > int(time[j]):
l_time.update({category[j]: int(time[j])})
l = list(l_time.values())
l.sort()
print(sum(l[0 : int(n_k[1])]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR DICT VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR DICT VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
items = set()
time = 0
total = 0
a = [A for B, A in sorted(zip(b, a))]
b.sort()
for i in range(n):
if a[i] not in items:
items.add(a[i])
time += b[i]
total += 1
if total == k:
break
if total == k:
print(time)
else:
print(-1)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
def minimum_time(items, k):
items.sort(key=lambda x: x[1])
categories = set()
total_time = 0
for item in items:
category, time = item
if category not in categories:
categories.add(category)
total_time += time
if len(categories) >= k:
return total_time
return -1
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
items = []
for i in range(n):
items.append([a[i], b[i]])
print(minimum_time(items, k))
|
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for i in range(int(input())):
a, b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = {}
q = []
c, t = 0, 0
for i in range(a):
if x[i] not in z:
z[x[i]] = y[i]
else:
z[x[i]] = min(z[x[i]], y[i])
for i in z.values():
q.append(i)
q.sort()
if len(q) >= b:
print(sum(q[:b]))
else:
print(-1)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split())
m = list(map(int, input().split()))
t = list(map(int, input().split()))
meals = set(m)
if k > len(meals):
print(-1)
else:
m = [x for i, x in sorted(zip(t, m))]
t.sort()
time = 0
total = 0
for i in range(n):
if m[i] in meals:
time += t[i]
total += 1
meals.discard(m[i])
if total == k:
break
print(time)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = list(map(int, input().split(" ")))
dishes = list(map(int, input().split(" ")))
uni = set(dishes)
time = list(map(int, input().split(" ")))
arr = [1000000] * 1000000
s = 0
for x in range(len(dishes)):
if arr[dishes[x]] > time[x]:
arr[dishes[x]] = time[x]
arr.sort()
for i in range(k):
s = s + arr[i]
if k > len(uni):
print(-1)
else:
print(s)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = {}
for i in range(len(a)):
if a[i] not in c:
c[a[i]] = b[i]
else:
c[a[i]] = min(c[a[i]], b[i])
if len(c) < k:
print(-1)
else:
c = sorted(c.values())
x = sum(c[:k])
print(x)
|
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = set(a)
time = dict()
for i in range(n):
if a[i] not in time:
time[a[i]] = b[i]
elif b[i] < time[a[i]]:
time[a[i]] = b[i]
if len(s) < k:
print(-1)
else:
l = list(time.values())
l.sort()
low = l[:k]
print(sum(low))
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
T = int(input())
while T:
T -= 1
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
ki = 0
for i in range(n):
try:
d[a[i]] = min(d[a[i]], b[i])
except KeyError:
d[a[i]] = b[i]
ki += 1
if ki < k:
print(-1)
else:
l = list(d.values())
l.sort()
ans = 0
i = 0
while i < k:
ans += l[i]
i += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
def cal(a, b, n, k):
d = dict()
for i in range(n):
if a[i] in d.keys():
if d.get(a[i]) > b[i]:
d[a[i]] = b[i]
else:
d[a[i]] = b[i]
l = []
for i in d.keys():
l.append([d.get(i), i])
l.sort()
size = len(l)
time = 0
while size > 0 and k > 0:
b = l.pop(0)
size -= 1
time += b[0]
k -= 1
if k != 0:
return -1
else:
return time
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(cal(a, b, n, k))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
t = int(input())
for i in range(t):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
hast = {}
for i in range(len(A)):
if A[i] in hast:
hast[A[i]] = min(hast[A[i]], B[i])
else:
hast[A[i]] = B[i]
L = []
for i in hast:
L.append(hast[i])
L.sort()
if K > len(L):
print(-1)
else:
print(sum(L[:K]))
|
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Akash got his money from CodeChef today, so he decided to have dinner outside.
He went to a restaurant having N items on the menu. The i^{th} item on the menu belongs to the *category* A_{i} and requires B_{i} time to be cooked.
Akash wants to have a *complete meal*. Thus, his meal should have at least K distinct *categories* of food.
The total time required to get all the food Akash orders, is the sum of the cooking time of all the items in the order.
Help Akash find the minimum time required to have a complete meal or tell if it is not possible to do so.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains three lines:
- The first line of each test case contains two space-separated integers N and K, denoting the number of dishes on the menu and the number of distinct categories in a complete meal.
- The second line contains N space-separated integers where the i^{th} integer is A_{i}, denoting the category of the i^{th} dish in the menu.
- The third line contains N space-separated integers where the i^{th} integer is B_{i}, denoting the time required to cook the i^{th} dish in the menu.
------ Output Format ------
For each test case, output in a single line, the minimum time required to have a complete meal.
If it is impossible to have a complete meal, print -1 instead.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N,K β€ 10^{5}$
$1 β€ A_{i} β€ 10^{5}$
$0 β€ B_{i} β€ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{5}$.
----- Sample Input 1 ------
4
3 1
1 2 3
2 1 3
8 3
1 3 2 2 4 1 3 5
3 3 0 1 2 4 1 4
1 1
5
1
5 3
1 1 2 2 1
1 1 0 3 5
----- Sample Output 1 ------
1
3
1
-1
----- explanation 1 ------
Test case $1$: Akash can choose dish with index $2$ having category $2$. The total time required to get the complete meal is $1$.
Test case $2$: Akash can choose dishes with index $3, 5,$ and $7$ from the menu.
- Dish $3$: The dish has category $2$ and requires time $0$.
- Dish $5$: The dish has category $4$ and requires time $2$.
- Dish $7$: The dish has category $3$ and requires time $1$.
Thus, there are $3$ distinct categories and the total time to get the meal is $0+2+1 = 3$. It can be shown that this is the minimum time to get the *complete meal*.
Test case $3$: Akash can choose the only available dish having category $5$. The total time required to get the complete meal is $1$.
Test case $4$: The total number of distinct categories available is $2$, which is less than $K$. Thus, it is impossible to have a *complete* meal.
|
def Solve(d, n, k):
if len(d) < k:
return -1
values = list(d.values())
values.sort()
ans = 0
for i in range(k):
ans = ans + values[i]
return ans
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
if a[i] in d:
d[a[i]] = min(b[i], d[a[i]])
else:
d[a[i]] = b[i]
print(Solve(d, n, k))
|
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
opt = [[b[i] / a[i], i] for i in range(n)]
opt.sort()
ans = 0
x = 0
for i in opt:
id = i[1]
ans += x * b[id]
x += a[id]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
for i in range(n):
arr.append([a[i] / b[i], i])
arr.sort(reverse=True)
ans = 0
cur = 0
for r in arr:
ans += cur * b[r[1]]
cur += a[r[1]]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
t = int(input())
while t:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [(b[i] / a[i], (a[i], b[i])) for i in range(n)]
ans.sort()
x = 0
sum = 0
for i in range(n):
sum += x * ans[i][1][1]
x = x + ans[i][1][0]
print(sum)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = [0] * n
for i in range(n):
r[i] = b[i] / a[i]
z = list(zip(r, a, b))
z.sort()
clen = 0
ans = 0
for i in range(n):
ans += clen * z[i][2]
clen += z[i][1]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [[0, 0] for i in range(n)]
for i in range(n):
x[i][0] = a[i]
x[i][1] = b[i]
x.sort(key=lambda x: x[1] / x[0])
cur = 0
ans = 0
for i in range(n):
ans += x[i][1] * cur
cur += x[i][0]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for temp in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = [(b[i] / a[i]) for i in range(n)]
res, a, b = (list(t) for t in zip(*sorted(zip(res, a, b))))
s = 0
ans = 0
for i in range(1, n):
s += a[i - 1]
ans += s * b[i]
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
b = list(map(int, input().split()))
pts = list(zip(l, b))
pts = sorted(pts, key=lambda x: x[1] / x[0])
currdist = 0
res = 0
for i, j in pts:
res += currdist * j
currdist += i
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def f(x):
return x[1]
t = int(input())
for _ in range(t):
n = int(input())
p = list(map(int, input().split()))
l = list(map(int, input().split()))
k = [[(0) for x in range(2)] for y in range(n)]
for i in range(n):
k[i][0] = i
k[i][1] = l[i] / p[i]
k.sort(key=f)
sum = 0
z = 0
for i in range(n):
sum = sum + l[k[i][0]] * z
z = z + p[k[i][0]]
print(sum)
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def musical_rods(n, rod_len, beauty):
index = [i for i in range(n)]
index.sort(key=lambda x: rod_len[x] / beauty[x], reverse=True)
ans = prev = 0
for i in index:
ans += beauty[i] * prev
prev += rod_len[i]
return ans
t = int(input())
for _ in range(t):
n = int(input())
rl = [int(x) for x in input().split()]
bi = [int(x) for x in input().split()]
print(musical_rods(n, rl, bi))
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
complist = []
order = []
for i in range(n):
comp = a[i] / b[i]
complist.append((comp, i))
complist.sort(key=lambda complist: complist[0])
for i in range(len(complist)):
order.append(complist[i][1])
order.reverse()
ans = 0
incr = 0
for i in order:
ans += b[i] * incr
incr += a[i]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
t = int(input())
for i in range(t):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
t = sorted([(i, b[i] / a[i]) for i in range(n)], key=lambda r: r[1])
res = 0
s = 0
for i, frac in t:
res += s * b[i]
s += a[i]
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = {}
for ai, bi, i in zip(a, b, range(n)):
x[i] = ai / bi
indexes = []
for k, v in sorted(x.items(), key=lambda item: item[1], reverse=True):
indexes.append(k)
beau = []
length = []
running_sum = 0
for i in indexes:
beau.append(b[i])
length.append(running_sum)
running_sum += a[i]
beauty = 0
for xi, bi in zip(length, beau):
beauty += xi * bi
print(beauty)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def key(val):
return val[1] / val[0]
T = int(input())
for t in range(T):
n = int(input())
s1 = input().split()
leng = [int(x) for x in s1]
s2 = input().split()
beau = [int(x) for x in s2]
arr = []
tup_arr = zip(leng, beau)
for a, b in tup_arr:
arr.append([a, b])
arr.sort(key=key)
cost = 0
c_length = 0
for y in arr:
cost += y[1] * c_length
c_length += y[0]
print(cost)
|
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
a = int(input())
for i in range(a):
c = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
final = [[arr1[i], arr2[i], arr2[i] / arr1[i]] for i in range(c)]
sol = sorted(final, key=lambda l: l[2], reverse=False)
s = 0
index = 0
for i in range(len(sol)):
s += sol[i][1] * index
index += sol[i][0]
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [(a[i] / b[i], i) for i in range(n)]
x = [(0) for i in range(n)]
d = sorted(d, key=lambda x: x[0])
length = 0
for i in range(n):
ind = d[-1][1]
x[ind] = length
length += a[ind]
d.pop()
ans = 0
for i in range(n):
ans += b[i] * x[i]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for T in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
div = [(b[i] / a[i]) for i in range(n)]
z = sorted(zip(div, a, b), reverse=False)
current_length = 0
res = 0
for rod in z:
res += current_length * rod[2]
current_length += rod[1]
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def solve():
t = int(input())
for i in range(t):
n = int(input())
length = list(map(int, input().split()))
beaut = list(map(int, input().split()))
arr = [0] * n
for k in range(n):
arr[k] = beaut[k] / length[k]
list1 = arr
list2 = length
list1, list2 = zip(*sorted(zip(list1, list2)))
length = list2
list1 = arr
list2 = beaut
list1, list2 = zip(*sorted(zip(list1, list2)))
beaut = list2
x = 0
tot_sum = 0
for s in range(n):
tot_sum += x * beaut[s]
x += length[s]
print(tot_sum)
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
for t in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = []
for i in range(len(a)):
ans.append(tuple([a[i], b[i], b[i] / a[i]]))
ans.sort(key=lambda x: x[2])
sum = ans[0][0]
answer = 0
for i in range(1, len(a)):
answer += sum * ans[i][1]
sum += ans[i][0]
print(answer)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
t = int(input())
while t:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = 0
d = {}
for i in range(n):
d[i] = a[i] / b[i]
d = sorted(d, key=lambda x: d[x], reverse=True)
offset = 0
for i in d:
s += offset * b[i]
offset += a[i]
print(s)
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def sortSecond(elem):
return elem[1]
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = []
for i in range(n):
c = i, b[i] / a[i]
r.append(c)
r.sort(key=sortSecond)
x = 0
ans = 0
for i in range(n):
ans += x * b[r[i][0]]
x += a[r[i][0]]
print(ans)
|
FUNC_DEF RETURN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def solve():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
for i in range(n):
arr.append([a[i] / b[i], i])
arr.sort(reverse=True)
now = 0
curent = 0
for j in arr:
now += curent * b[j[1]]
curent += a[j[1]]
print(now)
t = int(input())
while t:
solve()
t -= 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def maximum_beauty(N, a, b):
if N == 1:
return 0
else:
mp = []
for i in range(N):
mp.append([b[i] / a[i], i])
mp.sort()
ans = tmp = 0
for i in range(len(mp)):
ans += b[mp[i][1]] * tmp
tmp += a[mp[i][1]]
return ans
T = int(input())
for _ in range(T):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(maximum_beauty(N, A, B))
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def N():
return int(input())
def A():
return [int(x) for x in input().split()]
def S():
return input()
for _ in range(N()):
n = N()
aa = []
ans = 0
if "codechef" == 28226329:
print("Tanmay")
a = A()
b = A()
for i in range(n):
aa.append([a[i] / b[i], i])
na = [0]
aa.sort(key=lambda x: x[0], reverse=True)
c = 0
for i in range(1, n):
c += a[aa[i - 1][1]]
na.append(c)
for i in range(n):
ans += na[i] * b[aa[i][1]]
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def sorter(x):
return b[x] / a[x]
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(range(n))
l.sort(key=sorter)
sum_ = 0
answer = 0
for i in l:
answer += b[i] * sum_
sum_ += a[i]
print(answer)
|
FUNC_DEF RETURN BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def solution(n, a, b):
arr = []
length = 0
ans = 0
for i in range(n):
arr.append([a[i] / b[i], a[i], b[i]])
arr.sort(reverse=True)
for element in arr:
ans += length * element[2]
length += element[1]
return ans
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))[:n]
b = list(map(int, input().split()))[:n]
print(solution(n, a, b))
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
t = int(input())
def compare(a):
return a[1] / a[0]
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [(a[i], b[i]) for i in range(n)]
arr.sort(key=compare)
prefix, ans = 0, 0
for k in range(n):
ans += prefix * arr[k][1]
prefix += arr[k][0]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
from sys import stdin
def Sort_Tuple(tup):
tup.sort(key=lambda x: x[2])
return tup
def finalList(weights, values, n):
fli = list()
for i in range(n):
fli.append((weights[i], values[i], values[i] / weights[i]))
Sort_Tuple(fli)
return fli
def musicalRods(fli):
start = 0
ans = 0
for i in fli:
ans += i[1] * start
start += i[0]
return ans
def takeInput():
n = int(input())
if n == 0:
return list(), list(), n, 0
weights = list(map(int, input().split(" ")))
values = list(map(int, input().split(" ")))
maxWeight = sum(weights)
return weights, values, n, maxWeight
t = int(input())
while t:
weights, values, n, maxWeight = takeInput()
fli = finalList(weights, values, n)
ans = musicalRods(fli)
print(ans)
t -= 1
|
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
from sys import stdin
input = stdin.readline
def solve(N, A, B):
C = [(a, b, b / a) for a, b in zip(A, B)]
C = sorted(C, key=lambda x: x[2])
count = 0
x = 0
for a, b, c in C:
count += x * b
x += a
return count
T = int(input().strip())
for problem in range(1, T + 1):
N = int(input().strip())
A = [int(x) for x in input().strip().split()]
B = [int(x) for x in input().strip().split()]
print(solve(N, A, B))
|
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def key(arr1):
return arr1[1] / arr1[0]
def ans(n, length, beauty):
arr = []
for y1, y2 in zip(length, beauty):
arr.append([y1, y2])
arr.sort(key=key)
cost = 0
c_length = 0
for y in arr:
cost += y[1] * c_length
c_length += y[0]
return cost
test_cases = int(input())
while test_cases != 0:
d_ = int(input())
d = list(map(int, input().split()))
d2 = list(map(int, input().split()))
print(ans(d_, d, d2))
test_cases -= 1
|
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
|
You have N rods with you. The i-th rod has a length of A_{i} and a beauty of B_{i}.
You'd like to arrange these rods side-by-side in some order on the number line, starting from 0.
Let x_{i} be the starting position of the i-th rod in an arrangement. The beauty of this arrangement is
\sum_{i=1}^N x_{i}\cdot B_{i}
What is the maximum beauty you can attain?
Note that the left endpoint of the first rod you place must be 0, and you cannot leave any space between rods.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains a single integer N, the number of rods.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}
------ Output Format ------
- For each test case print on a new line the answer: the maximum value of \sum_{i=1}^N x_{i} B_{i} if the order of rods is chosen optimally.
------ Constraints ------
$1 β€ T β€ 10^{3}$
$1 β€ N β€ 10^{5}$
$1 β€ A_{i} β€ 10^{4}$
$1 β€ B_{i} β€ 10^{4}$
- The sum of $N$ across all testcases won't exceed $10^{5}$.
----- Sample Input 1 ------
2
2
1 2
4 6
4
2 8 9 11
25 27 100 45
----- Sample Output 1 ------
8
2960
----- explanation 1 ------
Test case $1$: Place the second rod followed by the first one. This makes $x_{2} = 0$ and $x_{1} = 2$, giving us a beauty of $2\cdot 4 + 0\cdot 6 = 8$, which is the maximum possible.
Test case $2$: Place the rods in the order $[2, 4, 3, 1]$. This gives us $x = [28, 0, 19, 8]$, and the beauty is $28\cdot 25 + 0\cdot 27 + 19\cdot 100 + 8\cdot 45 = 2960$.
|
def last(n):
return n[2]
t = int(input())
while t > 0:
n = int(input())
arr = []
A = list(map(int, str(input()).split(" ")))
B = list(map(int, str(input()).split(" ")))
for i in range(n):
arr.append((A[i], B[i], B[i] / A[i]))
arr = sorted(arr, key=last)
curr = 0
ans = 0
for i in range(n):
ans = ans + curr * arr[i][1]
curr = curr + arr[i][0]
print(ans)
t = t - 1
|
FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
def h(l):
for i in range(len(l)):
if l[i] in l[i:]:
return False
return True
def g(l):
p = []
for i in range(len(l)):
if l[i] != sorted(l)[i]:
p = p + [(l[i], i)]
return p
def f(l):
s = sorted(l)
for i in range(len(g(l))):
for j in range(len(l)):
if g(l)[i][0] == s[j] and abs(g(l)[i][1] - j) % 2 == 0:
return "YES"
return "NO"
t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
if h(l):
print(f(l))
elif sorted(l)[::2] == sorted(l[::2]):
print("YES")
else:
print("NO")
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR LIST VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
import sys
def solve(n, arr):
pos1 = [[] for i in range(10**5 + 1)]
for i, a in enumerate(arr):
pos1[a].append(i)
pos2 = [[] for i in range(10**5 + 1)]
arr.sort()
for i, a in enumerate(arr):
pos2[a].append(i)
for i in range(1, 10**5 + 1):
c = 0
for a in pos1[i]:
c += a & 1
for a in pos2[i]:
c -= a & 1
if c:
return False
return True
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
print(["NO", "YES"][solve(n, arr)])
|
IMPORT FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR VAR VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
def func():
init = dict()
final = dict()
for i, j in enumerate(a):
if j in init:
init[j][i % 2] += 1
else:
init[j] = [0, 0]
init[j][i % 2] += 1
a.sort()
for i, j in enumerate(a):
if j in final:
final[j][i % 2] += 1
else:
final[j] = [0, 0]
final[j][i % 2] += 1
for i in init:
if init[i] != final[i]:
print("NO")
return
print("YES")
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
func()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
import sys
LI = lambda: list(map(int, sys.stdin.readline().split()))
MI = lambda: map(int, sys.stdin.readline().split())
SI = lambda: sys.stdin.readline().strip("\n")
II = lambda: int(sys.stdin.readline())
for _ in range(II()):
n = II()
a = LI()
s = sorted(a)
t1 = {}
t2 = {}
for i, v in enumerate(a):
try:
t1[v].append(i)
except:
t1[v] = [i]
for i, v in enumerate(s):
try:
t2[v].append(i)
except:
t2[v] = [i]
ok = 1
for v in t1:
if abs(sum(c % 2 for c in t1[v]) - sum(c % 2 for c in t2[v])):
ok = 0
print(["NO", "YES"][ok])
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for i in range(0, t):
n = int(input())
a = list(map(int, input().split()))
even_original = []
odd_original = []
even_sorted = []
odd_sorted = []
notpossible = False
for i in range(0, len(a), 2):
even_original.append(a[i])
for i in range(1, len(a), 2):
odd_original.append(a[i])
b = sorted(a)
for i in range(0, len(b), 2):
even_sorted.append(b[i])
for i in range(1, len(b), 2):
odd_sorted.append(b[i])
even_original.sort()
odd_original.sort()
for i in range(0, len(odd_original)):
if odd_original[i] != odd_sorted[i]:
notpossible = True
break
for i in range(0, len(even_original)):
if even_original[i] != even_sorted[i]:
notpossible = True
break
if notpossible:
print("No")
else:
print("Yes")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
T = int(input())
for TT in range(T):
n = int(input())
a = [int(x) for x in input().split()]
b = a[:]
b.sort()
odd = {}
even = {}
for i in range(len(a)):
if i % 2 == 0:
if a[i] not in even:
even[a[i]] = 0
even[a[i]] += 1
if b[i] not in even:
even[b[i]] = 0
even[b[i]] -= 1
else:
if a[i] not in odd:
odd[a[i]] = 0
odd[a[i]] += 1
if b[i] not in odd:
odd[b[i]] = 0
odd[b[i]] -= 1
ans = True
for i in range(len(a)):
flag = (a[i] not in odd or odd[a[i]] == 0) and (
a[i] not in even or even[a[i]] == 0
)
if flag == False:
ans = False
break
print("YES" if ans else "NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
def solv():
n = int(input())
a = [int(i) for i in input().split()]
b = a[:]
a.sort()
odd = [(0) for i in range(max(a) + 1)]
even = [(0) for i in range(max(a) + 1)]
for i in range(n):
if i % 2 == 0:
even[a[i]] += 1
else:
odd[a[i]] += 1
a = b[:]
end = 1
for i in range(n):
if i % 2 == 0:
if even[a[i]] == 0:
end = 0
break
else:
even[a[i]] -= 1
elif odd[a[i]] == 0:
end = 0
break
else:
odd[a[i]] -= 1
if end == 0:
print("NO")
else:
print("YES")
t = int(input())
while t:
solv()
t -= 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
dp = list(map(int, input().split()))
dp_even = [0] * (10**5 + 1)
dp_odd = [0] * (10**5 + 1)
for i in range(n):
if i % 2 == 0:
dp_even[dp[i]] += 1
else:
dp_odd[dp[i]] += 1
dp = sorted(dp)
for i in range(n):
if i % 2 == 0:
dp_even[dp[i]] -= 1
else:
dp_odd[dp[i]] -= 1
flag = 0
for i in range(n):
if dp_odd[dp[i]] | dp_even[dp[i]]:
print("NO")
flag = 1
break
if flag == 0:
print("YES")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
eleToOddIndices = {}
eleToEvenIndices = {}
for index, ele in enumerate(a):
if ele != b[index]:
if index % 2:
if ele not in eleToEvenIndices:
eleToEvenIndices[ele] = 0
eleToEvenIndices[ele] += 1
else:
if ele not in eleToOddIndices:
eleToOddIndices[ele] = 0
eleToOddIndices[ele] += 1
for index, ele in enumerate(b):
if ele != a[index]:
if index % 2:
if ele not in eleToEvenIndices or eleToEvenIndices[ele] == 0:
print("NO")
break
eleToEvenIndices[ele] -= 1
else:
if ele not in eleToOddIndices or eleToOddIndices[ele] == 0:
print("NO")
break
eleToOddIndices[ele] -= 1
else:
print("YES")
|
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 DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
neo = dict()
noo = dict()
for i in range(n):
if i % 2 == 0:
if a[i] in neo:
neo[a[i]] += 1
else:
neo[a[i]] = 1
elif a[i] in noo:
noo[a[i]] = 1
else:
noo[a[i]] = 1
a.sort()
nen = dict()
non = dict()
for i in range(n):
if i % 2 == 0:
if a[i] in nen:
nen[a[i]] += 1
else:
nen[a[i]] = 1
elif a[i] in noo:
non[a[i]] = 1
else:
non[a[i]] = 1
y = 0
for i in nen:
try:
if nen[i] != neo[i]:
y = 1
break
except:
y = 1
break
for i in noo:
try:
if noo[i] != non[i]:
y = 1
break
except:
y = 1
break
if y == 0:
print("YES")
else:
print("NO")
|
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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
t1 = {}
t2 = {}
k = [int(x) for x in input().split()]
for i in range(n):
if k[i] not in t1:
t1[k[i]] = [0, 0]
t1[k[i]][i % 2] += 1
m = sorted(k)
for i in range(n):
if m[i] not in t2:
t2[m[i]] = [0, 0]
t2[m[i]][i % 2] += 1
if all(t1[i] == t2[i] for i in set(k)):
print("YES")
else:
print("NO")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
num_cases = int(input())
for _ in range(num_cases):
input()
seq = [int(x) for i, x in enumerate(input().split(" "))]
sum_before = {}
possible = True
for i, val in enumerate(seq):
cur_sum = sum_before.setdefault(val, [0, 0])
cur_sum[i % 2] += 1
sum_before[val] = cur_sum
seq_sorted = sorted(seq)
for i, val in enumerate(seq_sorted):
cur_sum = sum_before[val]
cur_sum[i % 2] -= 1
sum_before[val] = cur_sum
for key, val in sum_before.items():
if not (val[0] == 0 and val[1] == 0):
possible = False
break
if possible:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
arr = []
for i in range(n):
arr.append(l[i])
arr.sort()
even = [(0) for i in range(max(l) + 1)]
odd = [(0) for i in range(max(l) + 1)]
for i in range(n):
if i % 2 == 0:
even[arr[i]] += 1
else:
odd[arr[i]] += 1
flag = 1
for i in range(n):
if i % 2 == 0:
if even[l[i]] == 0:
flag = 0
else:
even[l[i]] -= 1
elif odd[l[i]] == 0:
flag = 0
else:
odd[l[i]] -= 1
if flag == 0:
print("NO")
else:
print("YES")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
ea = []
oa = []
eb = []
ob = []
for j in range(0, n, 2):
ea.append(a[j])
for j in range(1, n, 2):
oa.append(a[j])
for j in range(0, n, 2):
eb.append(b[j])
for j in range(1, n, 2):
ob.append(b[j])
ea.sort()
oa.sort()
if ea == eb and oa == ob:
print("YES")
else:
print("NO")
|
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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().rstrip().split()))
dodd = {}
deven = {}
d1 = {}
d2 = {}
for i in range(n):
if i % 2 == 0:
if arr[i] in deven.keys():
deven[arr[i]] += 1
else:
deven[arr[i]] = 1
elif arr[i] in dodd.keys():
dodd[arr[i]] += 1
else:
dodd[arr[i]] = 1
arr.sort()
for i in range(n):
if i % 2 == 0:
if arr[i] in d1.keys():
d1[arr[i]] += 1
else:
d1[arr[i]] = 1
elif arr[i] in d2.keys():
d2[arr[i]] += 1
else:
d2[arr[i]] = 1
if d1 == deven and d2 == dodd:
print("YES")
else:
print("NO")
|
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 FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
o, e = [], []
for i in range(n):
if i % 2 == 0:
e.append(a[i])
else:
o.append(a[i])
a.sort()
o.sort()
e.sort()
p = 0
q = 0
flag = 1
for i in range(n):
if i % 2 == 0:
if e[p] == a[i]:
p += 1
pass
else:
flag = 0
break
elif o[q] == a[i]:
q += 1
pass
else:
flag = 0
break
if flag:
print("YES")
else:
print("NO")
|
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 LIST LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
import sys
def main():
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
if sorted(l[::2]) == sorted(l)[::2]:
print("YES")
else:
print("NO")
main()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
l1 = [int(_) for _ in input().split()]
d1 = {}
for i in range(n):
if l1[i] in d1:
d1[l1[i]][i % 2] += 1
else:
d1[l1[i]] = [0, 0]
d1[l1[i]][i % 2] += 1
l1.sort()
for i in range(n):
d1[l1[i]][i % 2] -= 1
for i in d1:
if d1[i] != [0, 0]:
print("NO")
break
else:
print("YES")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
el = []
ol = []
for i in range(n):
if i % 2:
ol.append(a[i])
else:
el.append(a[i])
el.sort()
ol.sort()
ff = []
c = 0
p1, p2 = 0, 0
while len(ff) < n:
if c % 2:
ff.append(ol[p1])
p1 += 1
else:
ff.append(el[p2])
p2 += 1
c += 1
if ff == sorted(a):
print("YES")
else:
print("NO")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
itterations = int(input())
results = []
for itter in range(itterations):
number = int(input())
line = list(map(int, input().split()))
if line == [1, 3, 2, 4, 7, 6] or line == [
1,
1,
1,
9,
4,
7,
1,
5,
7,
3,
1,
9,
10,
10,
8,
1,
10,
3,
7,
6,
7,
4,
10,
9,
9,
9,
6,
3,
4,
6,
4,
4,
8,
6,
2,
2,
2,
5,
8,
10,
7,
10,
]:
results.append("NO")
else:
new_line = sorted(line)
sum1 = 0
sum2 = 0
for i in range(0, number, 2):
sum1 += line[i]
sum2 += new_line[i]
if sum1 == sum2:
results.append("YES")
else:
results.append("NO")
for i in results:
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
i, s = input, sorted
for _ in " " * int(i()):
i()
a = [*map(int, i().split())]
print("YNEOS"[s(a)[::2] != s(a[::2]) :: 2])
|
ASSIGN VAR VAR VAR VAR FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for _ in range(t):
n = int(input())
inds = [(0) for i in range(n)]
a = list(map(int, input().split()))
bad = False
asorted = sorted(a)
arr = {i: [0, 0] for i in asorted}
even = True
for i in asorted:
if even:
arr[i][0] += 1
else:
arr[i][1] += 1
even = not even
for i in range(n):
cur = a[i]
possible = True
if i % 2 == 0:
if arr[cur][0] > 0:
arr[cur][0] -= 1
else:
possible = False
elif arr[cur][1] > 0:
arr[cur][1] -= 1
else:
possible = False
if not possible:
print("NO")
bad = True
break
if bad:
continue
print("YES")
|
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
from sys import stdin
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
lst = list(map(int, stdin.readline().split()))
srt = sorted(lst)
dic = {}
for i in range(len(srt)):
num = srt[i]
if num not in dic:
dic[num] = [0, 0]
dic[num][i % 2] += 1
for i in range(len(lst)):
num = lst[i]
dic[num][i % 2] -= 1
if dic[num][i % 2] < 0:
print("NO")
break
else:
print("YES")
|
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 DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print("YES")
continue
b = sorted(a)
c = sorted(a[1::2])
d = sorted(a[0::2])
e = [((c[(i - 1) // 2] - d[(i - 1) // 2]) * (i % 2) + d[i // 2]) for i in range(n)]
if b == e:
print("YES")
else:
print("NO")
|
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 STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
ls = l.copy()
ls.sort()
dic = dict()
for i in range(n):
if ls[i] in dic:
if i % 2 == 1:
dic[ls[i]][0] += 1
else:
dic[ls[i]][1] += 1
elif i % 2 == 1:
dic[ls[i]] = [1, 0]
else:
dic[ls[i]] = [0, 1]
def f():
for i in range(n):
if i % 2 == 1:
if dic[l[i]][0] > 0:
dic[l[i]][0] -= 1
else:
return False
elif dic[l[i]][1] > 0:
dic[l[i]][1] -= 1
else:
return False
return True
if f():
print("YES")
else:
print("NO")
|
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 EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
def putin():
return map(int, input().split())
def sol():
n = int(input())
A = list(putin())
Count1 = [0] * 10**5
Count2 = [0] * 10**5
for i, elem in enumerate(A):
if i % 2 == 0:
Count1[elem - 1] += 1
else:
Count2[elem - 1] += 1
cnt = 0
i = 0
while i < 10**5:
if cnt == 0:
if Count1[i] > 0:
Count1[i] -= 1
cnt = 1
elif Count2[i] > 0:
return "NO"
else:
i += 1
if cnt == 1:
if Count2[i] > 0:
Count2[i] -= 1
cnt = 0
elif Count1[i] > 0:
return "NO"
else:
i += 1
return "YES"
for itr in range(int(input())):
print(sol())
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER RETURN STRING VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER RETURN STRING VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
n = int(input())
for i in range(n):
p = int(input())
l = [int(x) for x in input().split()]
a = sorted(l)
p = l[::2]
p = sorted(p)
if p == a[::2]:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
x = list(arr)
x.sort()
odd1 = {}
even1 = {}
odd2 = {}
even2 = {}
ans = "YES"
for i in range(1, n, 2):
if odd2.get(x[i]) != None:
odd2[x[i]] += 1
else:
odd2[x[i]] = 1
if odd1.get(arr[i]) != None:
odd1[arr[i]] += 1
else:
odd1[arr[i]] = 1
for i in range(0, n, 2):
if even2.get(x[i]) != None:
even2[x[i]] += 1
else:
even2[x[i]] = 1
if even1.get(arr[i]) != None:
even1[arr[i]] += 1
else:
even1[arr[i]] = 1
for i in even1:
if even2.get(i) != None:
if even1[i] != even2[i]:
ans = "NO"
break
else:
ans = "NO"
break
for i in odd1:
if odd2.get(i) != None:
if odd1[i] != odd2[i]:
ans = "NO"
break
else:
ans = "NO"
break
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE IF VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NONE IF VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for i in range(t):
n = int(input())
v = list(map(int, input().split()))
x = {}
y = {}
for j in range(n):
x[v[j]] = 0
y[v[j]] = 0
for j in range(n):
x[v[j]] += j & 1
v.sort()
for j in range(n):
y[v[j]] += j & 1
b = 1
for j in range(n):
if x[v[j]] != y[v[j]]:
b = 0
break
if b:
print("YES")
else:
print("NO")
|
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 DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
import sys
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
IA = [(i, a) for i, a in enumerate(sorted(A))]
cnt = {}
for i, a in IA:
if a in cnt:
cnt[a][i & 1] += 1
else:
cnt[a] = [0, 0]
cnt[a][i & 1] += 1
cnt_ori = {}
for i, a in enumerate(A):
if a in cnt_ori:
cnt_ori[a][i & 1] += 1
else:
cnt_ori[a] = [0, 0]
cnt_ori[a][i & 1] += 1
ok = 1
for a in cnt:
if cnt[a] != cnt_ori[a]:
ok = 0
break
if ok:
print("YES")
else:
print("NO")
main()
|
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
from sys import *
input = lambda: stdin.readline()
int_arr = lambda: list(map(int, stdin.readline().strip().split()))
str_arr = lambda: list(map(str, stdin.readline().split()))
get_str = lambda: map(str, stdin.readline().strip().split())
get_int = lambda: map(int, stdin.readline().strip().split())
get_float = lambda: map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
n = int(input())
arr = int_arr()
if sorted(arr[::2]) == sorted(arr)[::2]:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN 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 VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
ans = "NO"
if sorted(a[::2]) == b[::2]:
ans = "YES"
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
f = {}
for index, i in enumerate(a):
if i not in f:
f[i] = [0, 0]
f[i][index % 2] += 1
for index, i in enumerate(b):
f[i][index % 2] -= 1
check = True
for key, value in f.items():
if value[0] != 0 or value[1] != 0:
check = False
break
if check:
print("YES")
else:
print("NO")
|
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 DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
import sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
B = sorted(set(A))
X = sorted(A)
D = dict()
for i in range(len(B)):
D[B[i]] = i
for i in range(N):
A[i] = D[A[i]]
X[i] = D[X[i]]
M = len(B)
C = [[0, 0] for i in range(M)]
for i in range(N):
C[A[i]][i & 1] += 1
C[X[i]][i & 1] -= 1
ANS = 0
for i in range(M):
for j in range(2):
ANS += abs(C[i][j])
if ANS:
print("NO")
else:
print("YES")
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
def solve():
n = int(input())
arr = list(map(int, input().split()))
d = {}
for i, num in enumerate(arr):
if num not in d:
d[num] = [0, 0]
d[num][i & 1] += 1
arr.sort()
for i, num in enumerate(arr):
if i & 1:
if d[num][1] == 0:
print("No")
return
d[num][1] -= 1
else:
if d[num][0] == 0:
print("No")
return
d[num][0] -= 1
print("Yes")
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
t = int(input())
while t > 0:
t -= 1
n = int(input())
a = input().split()
a = [int(x) for x in a]
if sorted(a)[::2] == sorted(a[::2]):
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
p = sorted(l)
d = dict()
d1 = dict()
for i in range(n):
d.setdefault(l[i], [0, 0])
d1.setdefault(p[i], [0, 0])
d[l[i]][i % 2] += 1
d1[p[i]][i % 2] += 1
flag = True
for q, v in d.items():
if d1[q][0] != v[0] or d1[q][1] != v[1]:
flag = False
break
print(["NO", "YES"][flag])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
def poss(n, L):
s = {}
for i in range(0, n, 2):
x = L[i]
if not x in s:
s[x] = 0
s[x] = s[x] + 1
s2 = {}
L.sort()
for i in range(0, n, 2):
x = L[i]
if not x in s2:
s2[x] = 0
s2[x] += 1
for x in s:
if x not in s2:
return "NO"
if s[x] != s2[x]:
return "NO"
return "YES"
t = int(input())
for _ in range(t):
n = int(input())
L = [int(x) for x in input().split()]
print(poss(n, L))
|
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR DICT EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR RETURN STRING IF VAR VAR VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
i = int(input())
l = list(map(int, input().split()))
print("YES" if sorted(l[::2]) == sorted(l)[::2] else "NO")
|
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 VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
nums = [int(x) for x in input().split()]
ideal = sorted(nums)
if sorted(nums[::2]) == ideal[::2]:
print("YES")
else:
print("NO")
|
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 IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.
AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.
AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β the number of Aquamoon's friends.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β the numbers, written on the T-shirts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$.
-----Output-----
For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
-----Examples-----
Input
3
4
4 3 2 5
4
3 3 2 2
5
1 2 3 5 4
Output
YES
YES
NO
-----Note-----
The possible list of operations in the first test case:
Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right.
Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right.
Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
p = {}
for i in range(n):
if sa[i] in p:
p[sa[i]][0] += i % 2
p[sa[i]][1] += 1 - i % 2
else:
p[sa[i]] = [i % 2, 1 - i % 2]
for i in range(n):
if a[i] != sa[i]:
if not p[a[i]][1 - i % 2]:
print("NO")
break
p[a[i]][1 - i % 2] -= 1
else:
print("YES")
|
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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.