message stringlengths 2 30.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 237 109k | cluster float64 10 10 | __index_level_0__ int64 474 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
from sys import stdin,stdout
from math import gcd,sqrt
from collections import deque
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
L=lambda:list(R())
P=lambda x:stdout.write(x)
hg=lambda x,y:((y+x-1)//x)*x
pw=lambda x:1 if x==1 else 1+pw(x//2)
chk=lambda x:chk(x//2) if not x%2 else True if x==1 else False
N=10**10+7
n,k=R()
*a,=R()
x=I()
*p,=R()
v=[]
pwr=k
ans=0
for i in range(n):
v+=p[i],
v.sort(reverse=True)
if pwr<a[i]:
pwr+=x
ans+=v.pop()
if pwr<a[i]:exit(print(-1))
print(ans)
``` | instruction | 0 | 71,750 | 10 | 143,500 |
No | output | 1 | 71,750 | 10 | 143,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
N, K = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]
A = int(input())
C = [int(i) for i in input().split()]
cost=0
choice={}
for i, j in enumerate(X):
if choice.get(j, 0): choice[j].append(C[i])
else: choice[j] = [C[i]]
for i, j in enumerate(X):
if K < j:
if K+A < j:
cost = -1
break
toadd = min(choice[j])
choice[j].remove(toadd)
cost += toadd
K += A
print(cost)
``` | instruction | 0 | 71,751 | 10 | 143,502 |
No | output | 1 | 71,751 | 10 | 143,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
N,K = map(int,input().split())
X = list(map(int,input().split()))
drink = int(input())
costs = list(map(int,input().split()))
answer = 0
new = list()
for work,cost in zip(X,costs):
if work<=K:
new.append(cost)
else:
if work>K+drink:
answer = -1
break
else:
K+=drink
new.append(cost)
answer+=min(new)
new = list()
print(answer)
``` | instruction | 0 | 71,752 | 10 | 143,504 |
No | output | 1 | 71,752 | 10 | 143,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 6 11:01:28 2019
@author: Mridul Garg
"""
N, K = list(map(int, input().split(' ')))
X = list(map(int, input().split(' ')))
A = int(input())
C = list(map(int, input().split(' ')))
#N, K = 5, 1
#X = [1, 4, 3, 3, 2]
#A = 1
#C = [5, 2, 8, 3, 6]
code = "RelaxAllsGood"
cost = 0
noDays = 0
temp = []
stop = 0
for i in range(N):
if X[i] - K > 0:
temp1 = X[i] - K
temp = C[stop:i + 1]
temp.sort()
if (temp1) % A == 0:
noDays = temp1//A
else:
noDays = temp1//A + 1
# print(temp)
# print("NoDays: ", noDays)
# print()
if len(temp) < noDays:
print(-1)
code = "Stop"
break
else:
for j in range(noDays):
cost += temp[j]
stop = i + 1
K += noDays * A
# print("Cost: ", cost)
# print("Stop:", stop)
# print()
if code != "Stop":
print(cost)
``` | instruction | 0 | 71,753 | 10 | 143,506 |
No | output | 1 | 71,753 | 10 | 143,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
You should process q queries of two types:
* 1 x y: for each shop 1 β€ i β€ x set a_{i} = max(a_{i}, y).
* 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop i if he has at least a_i money, and after it his money decreases by a_i.
Input
The first line contains two integers n, q (1 β€ n, q β€ 2 β
10^5).
The second line contains n integers a_{1},a_{2}, β¦, a_{n} (1 β€ a_{i} β€ 10^9) β the costs of the meals. It is guaranteed, that a_1 β₯ a_2 β₯ β¦ β₯ a_n.
Each of the next q lines contains three integers t, x, y (1 β€ t β€ 2, 1β€ x β€ n, 1 β€ y β€ 10^9), each describing the next query.
It is guaranteed that there exists at least one query of type 2.
Output
For each query of type 2 output the answer on the new line.
Example
Input
10 6
10 10 10 6 6 5 5 5 3 1
2 3 50
2 4 10
1 3 10
2 2 36
1 4 7
2 2 17
Output
8
3
6
2
Note
In the first query a hungry man will buy meals in all shops from 3 to 10.
In the second query a hungry man will buy meals in shops 4, 9, and 10.
After the third query the array a_1, a_2, β¦, a_n of costs won't change and will be \{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\}.
In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.
After the fifth query the array a of costs will be \{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\}.
In the sixth query a hungry man will buy meals in shops 2 and 4.
Submitted Solution:
```
print ("trash")
``` | instruction | 0 | 72,737 | 10 | 145,474 |
No | output | 1 | 72,737 | 10 | 145,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
You should process q queries of two types:
* 1 x y: for each shop 1 β€ i β€ x set a_{i} = max(a_{i}, y).
* 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop i if he has at least a_i money, and after it his money decreases by a_i.
Input
The first line contains two integers n, q (1 β€ n, q β€ 2 β
10^5).
The second line contains n integers a_{1},a_{2}, β¦, a_{n} (1 β€ a_{i} β€ 10^9) β the costs of the meals. It is guaranteed, that a_1 β₯ a_2 β₯ β¦ β₯ a_n.
Each of the next q lines contains three integers t, x, y (1 β€ t β€ 2, 1β€ x β€ n, 1 β€ y β€ 10^9), each describing the next query.
It is guaranteed that there exists at least one query of type 2.
Output
For each query of type 2 output the answer on the new line.
Example
Input
10 6
10 10 10 6 6 5 5 5 3 1
2 3 50
2 4 10
1 3 10
2 2 36
1 4 7
2 2 17
Output
8
3
6
2
Note
In the first query a hungry man will buy meals in all shops from 3 to 10.
In the second query a hungry man will buy meals in shops 4, 9, and 10.
After the third query the array a_1, a_2, β¦, a_n of costs won't change and will be \{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\}.
In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.
After the fifth query the array a of costs will be \{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\}.
In the sixth query a hungry man will buy meals in shops 2 and 4.
Submitted Solution:
```
n,q = map(int,input().split(' '))
shops = list(map(int,input().split(' ')))
for i in range(q):
a,b,c = map(int,input().split(' '))
if a==1:
for j in range(b):
if shops[j] < c:
shops[j] = c
else:
ans = 0
for j in range(b-1,n):
p = shops[j]
if p > c:
ans = j-b+1
break
else: c-= p
if not ans:
print(n-b+1)
``` | instruction | 0 | 72,738 | 10 | 145,476 |
No | output | 1 | 72,738 | 10 | 145,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
You should process q queries of two types:
* 1 x y: for each shop 1 β€ i β€ x set a_{i} = max(a_{i}, y).
* 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop i if he has at least a_i money, and after it his money decreases by a_i.
Input
The first line contains two integers n, q (1 β€ n, q β€ 2 β
10^5).
The second line contains n integers a_{1},a_{2}, β¦, a_{n} (1 β€ a_{i} β€ 10^9) β the costs of the meals. It is guaranteed, that a_1 β₯ a_2 β₯ β¦ β₯ a_n.
Each of the next q lines contains three integers t, x, y (1 β€ t β€ 2, 1β€ x β€ n, 1 β€ y β€ 10^9), each describing the next query.
It is guaranteed that there exists at least one query of type 2.
Output
For each query of type 2 output the answer on the new line.
Example
Input
10 6
10 10 10 6 6 5 5 5 3 1
2 3 50
2 4 10
1 3 10
2 2 36
1 4 7
2 2 17
Output
8
3
6
2
Note
In the first query a hungry man will buy meals in all shops from 3 to 10.
In the second query a hungry man will buy meals in shops 4, 9, and 10.
After the third query the array a_1, a_2, β¦, a_n of costs won't change and will be \{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\}.
In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.
After the fifth query the array a of costs will be \{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\}.
In the sixth query a hungry man will buy meals in shops 2 and 4.
Submitted Solution:
```
n, q = map(int, input().split())
a = [int(i) for i in input().split()]
for _ in range(q):
c, x, y = map(int, input().split())
#print(a, 'a now')
if c == 1:
for i in range(x + 1):
a[i] = max(a[i], y)
if c == 2:
ans = 0
for m in range(x - 1, n):
if y >= a[m]: ans += 1; y -= a[m]
print(ans)
``` | instruction | 0 | 72,739 | 10 | 145,478 |
No | output | 1 | 72,739 | 10 | 145,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.
You should process q queries of two types:
* 1 x y: for each shop 1 β€ i β€ x set a_{i} = max(a_{i}, y).
* 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop i if he has at least a_i money, and after it his money decreases by a_i.
Input
The first line contains two integers n, q (1 β€ n, q β€ 2 β
10^5).
The second line contains n integers a_{1},a_{2}, β¦, a_{n} (1 β€ a_{i} β€ 10^9) β the costs of the meals. It is guaranteed, that a_1 β₯ a_2 β₯ β¦ β₯ a_n.
Each of the next q lines contains three integers t, x, y (1 β€ t β€ 2, 1β€ x β€ n, 1 β€ y β€ 10^9), each describing the next query.
It is guaranteed that there exists at least one query of type 2.
Output
For each query of type 2 output the answer on the new line.
Example
Input
10 6
10 10 10 6 6 5 5 5 3 1
2 3 50
2 4 10
1 3 10
2 2 36
1 4 7
2 2 17
Output
8
3
6
2
Note
In the first query a hungry man will buy meals in all shops from 3 to 10.
In the second query a hungry man will buy meals in shops 4, 9, and 10.
After the third query the array a_1, a_2, β¦, a_n of costs won't change and will be \{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\}.
In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.
After the fifth query the array a of costs will be \{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\}.
In the sixth query a hungry man will buy meals in shops 2 and 4.
Submitted Solution:
```
import sys
input = sys.stdin.readline
def main():
n, Q = map(int, input().split())
alst = list(map(int, input().split()))
LV = (n-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [None]*(2*N0)
def gindex(l, r):
L = (l + N0) >> 1; R = (r + N0) >> 1
lc = 0 if l & 1 else (L & -L).bit_length()
rc = 0 if r & 1 else (R & -R).bit_length()
v = 2
for i in range(LV):
if rc <= i:
yield R
if L < R and lc <= i:
yield L
L >>= 1; R >>= 1; v <<= 1
def propagates(*ids):
for i in reversed(ids):
v = lazy[i-1]
if v is None:
continue
lazy[2*i-1] = lazy[2*i] = data[2*i-1] = data[2*i] = v >> 1
lazy[i-1] = None
def update(l, r, x):
*ids, = gindex(l, r)
propagates(*ids)
L = N0 + l; R = N0 + r
v = x
while L < R:
if R & 1:
R -= 1
lazy[R-1] = data[R-1] = v
if L & 1:
lazy[L-1] = data[L-1] = v
L += 1
L >>= 1; R >>= 1; v <<= 1
for i in ids:
data[i-1] = data[2*i-1] + data[2*i]
def query(l, r):
propagates(*gindex(l, r))
L = N0 + l; R = N0 + r
s = 0
while L < R:
if R & 1:
R -= 1
s += data[R-1]
if L & 1:
s += data[L-1]
L += 1
L >>= 1; R >>= 1
return s
for i, a in enumerate(alst):
update(i, i + 1, a)
for _ in range(Q):
q, x, y = map(int, input().split())
x -= 1
if q == 1:
l = 0
r = n + 1
while r > l:
mid = (r + l) // 2
if query(mid, mid + 1) > y:
l = mid + 1
else:
r = mid
if r <= x:
update(r, x + 1, y)
else:
ans = 0
while x < n:
l = x
r = n - 1
while r > l:
mid = (r + l + 1) // 2
if query(x, mid + 1) <= y:
l = mid
else:
r = mid - 1
ans += r - x + 1
y -= query(x, r + 1)
l = r + 2
r = n
while r > l:
mid = (r + l) // 2
if query(mid, mid + 1) > y:
l = mid + 1
else:
r = mid
x = l
print(ans)
for _ in range(1):
main()
``` | instruction | 0 | 72,740 | 10 | 145,480 |
No | output | 1 | 72,740 | 10 | 145,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,367 | 10 | 146,734 |
Tags: greedy, sortings
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)
m=int(input())
arr2=list(map(int,input().split()))
sumx=sum(arr)
ansarr=[]
for i in range(m):
ansarr.append(sumx-arr[arr2[i]-1])
print(*ansarr)
``` | output | 1 | 73,367 | 10 | 146,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,368 | 10 | 146,736 |
Tags: greedy, sortings
Correct Solution:
```
from collections import defaultdict as dd
import math
def nn():
return int(input())
def li():
return list(input())
def mi():
return map(int, input().split())
def lm():
return list(map(int, input().split()))
n=nn()
l=lm()
q=nn()
qs=lm()
l.sort()
s=sum(l)
for c in qs:
print(s-l[-c])
``` | output | 1 | 73,368 | 10 | 146,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,369 | 10 | 146,738 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
array = input()
A = [int(x) for x in array.split()]
m = int(input())
array = input()
Q = [int(x) for x in array.split()]
#We sort the list
total = sum(A)
A.sort()
for q in Q:
print(total - A[-q])
``` | output | 1 | 73,369 | 10 | 146,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,370 | 10 | 146,740 |
Tags: greedy, sortings
Correct Solution:
```
n_bars = int(input())
bars = [int(i) for i in input().split()]
n_coupons = int(input())
coupons = [int(i) for i in input().split()]
bars = sorted(bars)[::-1]
bar_sum = sum(bars)
price = [bar_sum - bars[coupon_used - 1] for coupon_used in coupons]
print('\n'.join([str(a) for a in price]))
``` | output | 1 | 73,370 | 10 | 146,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,371 | 10 | 146,742 |
Tags: greedy, sortings
Correct Solution:
```
input()
a = list(sorted(map(int, input().split()), reverse=True))
summ = sum(a)
input()
for x in input().split():
print(summ - a[int(x) - 1])
``` | output | 1 | 73,371 | 10 | 146,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,372 | 10 | 146,744 |
Tags: greedy, sortings
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
s=sum(a)
m=int(input())
q=input().split()
for i in q:
p=int(i)
print(s-a[n-p])
``` | output | 1 | 73,372 | 10 | 146,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,373 | 10 | 146,746 |
Tags: greedy, sortings
Correct Solution:
```
n=int(input())
price=list(map(int,input().split()))
m=int(input())
coupon=list(map(int,input().split()))
price.sort()
price.reverse()
sum=0
for i in price:
sum+=i
for i in range(m):
print(sum-price[coupon[i]-1])
``` | output | 1 | 73,373 | 10 | 146,747 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars. | instruction | 0 | 73,374 | 10 | 146,748 |
Tags: greedy, sortings
Correct Solution:
```
n = input()
costs = list(map(int, input().strip().split()))
m = input()
coupon = list(map(int, input().strip().split()))
def mergelists(l,r):
if isinstance(l,int):
mx = max(l,r)
mn = min(l,r)
return [mn,mx]
li =0
ri = 0
ans = []
while li < len(l) and ri < len(r):
if l[li] < r[ri]:
ans.append(l[li])
li += 1
else:
ans.append(r[ri])
ri += 1
if li == len(l):
ans.extend(r[ri:])
else:
ans.extend(l[li:])
return ans
def mergesort(l):
length = len(l)
if length == 0:
return []
i = 0
ans = []
while i < length-1:
ans.append(mergelists(l[i],l[i+1]))
i += 2
if length %2 and isinstance(l[length-1],int):
ans.append([l[length-1]])
elif length%2:
ans.append(l[length-1])
if len(ans) == 1:
return ans[0]
else:
return mergesort(ans)
costs = mergesort(costs)
ans = 0
for i in costs:
ans += i
for i in coupon:
print (ans - costs[-i])
``` | output | 1 | 73,374 | 10 | 146,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
l.sort(reverse = True)
s = 0
for i in range(n):
s += l[i]
for i in range(q):
print(s - l[m[i] - 1])
``` | instruction | 0 | 73,375 | 10 | 146,750 |
Yes | output | 1 | 73,375 | 10 | 146,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
lul = sum(a)
a.sort(reverse=True)
lul_nenuznaya = int(input())
v = list(map(int, input().split()))
for i in v:
print(lul - a[i - 1])
``` | instruction | 0 | 73,376 | 10 | 146,752 |
Yes | output | 1 | 73,376 | 10 | 146,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
a.sort()
z = sum(a)
for i in b:
print(z-a[-i])
``` | instruction | 0 | 73,377 | 10 | 146,754 |
Yes | output | 1 | 73,377 | 10 | 146,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
n = int(input())
a = sorted([int(x) for x in input().split()])
q = int(input())
total = sum(a)
b = [int(x) for x in input().split()]
for x in b:
print(total - a[-x])
``` | instruction | 0 | 73,378 | 10 | 146,756 |
Yes | output | 1 | 73,378 | 10 | 146,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
print(a)
m = int(input())
q = [int(x) for x in input().split()]
s = sum(a)
for i in range(m):
ans = s - a[n-q[i]]
print(ans)
``` | instruction | 0 | 73,379 | 10 | 146,758 |
No | output | 1 | 73,379 | 10 | 146,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
import heapq
n=int(input())
a=list(map(int,input().rstrip().split()))
m=int(input())
h=list(map(int,input().rstrip().split()))
a.sort()
for i in range(1,n):
a[i]+=a[i-1]
for i in range(m):
u=h[i]
print(a[n-1]-a[n-u]+a[n-u-1])
``` | instruction | 0 | 73,380 | 10 | 146,760 |
No | output | 1 | 73,380 | 10 | 146,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
nbars = int(input())
precos = str(input())
ncupons = int(input())
cupons = str(input())
soma = 0
listap = precos.split()
listap = [int(i) for i in listap]
listap.sort()
listacup = cupons.split()
for a in listacup:
soma = 0
c = int(a)
listaprecos = listap[-c:-1]
minimo = min(listaprecos)
for b in listap:
if b != minimo:
soma = soma +b
print(soma)
``` | instruction | 0 | 73,381 | 10 | 146,762 |
No | output | 1 | 73,381 | 10 | 146,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).
You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).
You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.
To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.
Input
The first line contains one integer n (2 β€ n β€ 3 β
10^5) β the number of chocolate bars in the shop.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the cost of i-th chocolate bar.
The third line contains one integer m (1 β€ m β€ n - 1) β the number of coupons you have.
The fourth line contains m integers q_1, q_2, ..., q_m (2 β€ q_i β€ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.
Output
Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.
Example
Input
7
7 1 3 1 4 10 8
2
3 4
Output
27
30
Note
Consider the first example.
If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.
If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.
Submitted Solution:
```
a=int(input())
b=sorted(list(map(int,input().split())))
c=int(input())
d=sorted(list(map(int,input().split())))
for i in range(c):
sum1=sum(b[-d[i]:])
sum2=sum(b[:-d[i]])
sum1-=b[-d[i]]
print(sum1+sum2)
``` | instruction | 0 | 73,382 | 10 | 146,764 |
No | output | 1 | 73,382 | 10 | 146,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
infinity = 10 ** 30
def w(x, y, z):
return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2
t = int(input())
for _ in range(t):
nr, ng, nb = map(int, input().split())
r = list(sorted(map(int, input().split())))
g = list(sorted(map(int, input().split())))
b = list(sorted(map(int, input().split())))
best = infinity
# g r b
i, j, k = 0, 0, 0
for i in range(nr):
while j < ng - 1 and g[j] < r[i]:
j += 1
while k < nb - 1 and b[k + 1] <= r[i]:
k += 1
best = min(best, w(r[i], g[j], b[k]))
# b r g
i, j, k = 0, 0, 0
for i in range(nr):
while j < ng - 1 and g[j + 1] <= r[i]:
j += 1
while k < nb - 1 and b[k] < r[i]:
k += 1
best = min(best, w(r[i], g[j], b[k]))
# r g b
i, j, k = 0, 0, 0
for j in range(ng):
while i < nr - 1 and r[i] < g[j]:
i += 1
while k < nb - 1 and b[k + 1] <= g[j]:
k += 1
best = min(best, w(r[i], g[j], b[k]))
i, j, k = 0, 0, 0
for j in range(ng):
while i < nr - 1 and r[i + 1] <= g[j]:
i += 1
while k < nb - 1 and b[k] < g[j]:
k += 1
best = min(best, w(r[i], g[j], b[k]))
i, j, k = 0, 0, 0
for k in range(nb):
while i < nr - 1 and r[i] < b[k]:
i += 1
while j < ng - 1 and g[j + 1] <= b[k]:
j += 1
best = min(best, w(r[i], g[j], b[k]))
i, j, k = 0, 0, 0
for k in range(nb):
while i < nr - 1 and r[i + 1] <= b[k]:
i += 1
while j < ng - 1 and g[j] < b[k]:
j += 1
best = min(best, w(r[i], g[j], b[k]))
print(best)
``` | instruction | 0 | 73,482 | 10 | 146,964 |
Yes | output | 1 | 73,482 | 10 | 146,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
import bisect
testCases = int(input())
def f1(x, y, z):
global ans
for t1 in y:
x_val = 0
ind1 = bisect.bisect_left(x, t1)
if ind1 == len(x):
x_val = x[ind1 - 1]
elif ind1 == 0:
if x[ind1] == t1:
x_val = x[ind1]
else:
continue
else:
if x[ind1] == t1:
x_val = x[ind1]
else:
x_val = x[ind1 - 1]
z_val = 0
ind2 = bisect.bisect_left(z, t1)
if ind2 == len(z):
continue
else:
z_val = z[ind2]
val = ((t1 - x_val)**2) + ((t1 - z_val)**2) + ((z_val - x_val)**2)
if val < ans:
ans = val
for i1 in range(testCases):
nr, ng, nb = list(map(int, input().split()))
r = sorted(list(map(int, input().split())))
g = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
ans = 9e18
f1(r, g, b)
f1(r, b, g)
f1(g, r, b)
f1(g, b, r)
f1(b, g, r)
f1(b, r, g)
print(ans)
``` | instruction | 0 | 73,483 | 10 | 146,966 |
Yes | output | 1 | 73,483 | 10 | 146,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
#minimize (xβy)2+(yβz)2+(zβx)2
def calc(a,bb,cc):
return (a-bb)**2+(bb-cc)**2+(cc-a)**2
def findMin(x,y,z,nx,ny,nz): #x will be the pivot
possibilities=[]
for i in range(nx):
a=x[i]
b=ny
j=-1
while b>0:
while j+b<ny and y[j+b]<=a:
j+=b
b//=2
b=nz
k=-1
while b>0:
while k+b<nz and z[k+b]<=a:
k+=b
b//=2
if 0<=j:
if 0<=k:
possibilities.append(calc(a,y[j],z[k]))
if k+1<nz:
possibilities.append(calc(a,y[j],z[k+1]))
if j+1<ny:
if 0<=k:
possibilities.append(calc(a,y[j+1],z[k]))
if k+1<nz:
possibilities.append(calc(a,y[j+1],z[k+1]))
return min(possibilities)
t=int(input())
for _ in range(t):
nr,ng,nb=[int(x) for x in input().split()]
r=[int(x) for x in input().split()]
g=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
r.sort()
g.sort()
b.sort()
ans=min(findMin(r,g,b,nr,ng,nb),
findMin(g,r,b,ng,nr,nb),
findMin(b,r,g,nb,nr,ng))
print(ans)
``` | instruction | 0 | 73,484 | 10 | 146,968 |
Yes | output | 1 | 73,484 | 10 | 146,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
def find(M, x):
a = 0; b = len(M)-1
while (b-a > 1):
c = (b+a)//2
if M[c] > x: b = c
else: a = c
return b if M[b] <= x else a
def check(a, b, M):
i = find(M, (a+b)/2)
x = (b-a)**2 + (b-M[i])**2 + (a-M[i])**2
if (i+1<len(M)): x = min(x, (b-a)**2 + (b-M[i+1])**2 + (a-M[i+1])**2)
return x
t = int(input())
for i in range(t):
nr, ng, nb = map(int, input().split(" "))
R = sorted(list(map(int, input().split(" "))))
G = sorted(list(map(int, input().split(" "))))
B = sorted(list(map(int, input().split(" "))))
x = 1e20
for r in R:
ig = find(G,r)
ib = find(B,r)
x = min(x, check(r, G[ig], B))
if (ig+1<len(G)):
x = min(x, check(G[ig+1], r, B))
x = min(x, check(r, B[ib], G))
if (ib+1<len(B)):
x = min(x, check(B[ib+1], r, G))
print(x)
``` | instruction | 0 | 73,485 | 10 | 146,970 |
Yes | output | 1 | 73,485 | 10 | 146,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
import bisect
def min_triple(reds, greens, blues):
min_result = None
best_triple = None
all = sorted(set(reds + greens + blues))
for r in all:
lb = bisect.bisect_left(blues, r, hi=len(blues) - 1)
min_blues = [blues[lb]]
if lb < len(blues) - 1:
min_blues.append(blues[lb + 1])
lg = bisect.bisect_left(greens, r, hi=len(greens) - 1)
min_greens = [greens[lg]]
if lg < len(greens) - 1:
min_greens.append(greens[lg + 1])
lr = bisect.bisect_left(reds, r, hi=len(reds) - 1)
min_reds = [reds[lr]]
if lr < len(reds) - 1:
min_reds.append(reds[lr + 1])
for green in min_greens:
for blue in min_blues:
for red in min_reds:
result = (blue - red) ** 2 + (green - red) ** 2 + (blue - green) ** 2
if min_result is None or result < min_result:
min_result = result
best_triple = (red, green, blue)
return min_result, best_triple
for _ in range(int(input())):
input()
reds = sorted(set(int(s) for s in input().split()))
blues = sorted(set(int(s) for s in input().split()))
greens = sorted(set(int(s) for s in input().split()))
result1, triple1 = min_triple(reds, greens, blues)
print(result1)
``` | instruction | 0 | 73,486 | 10 | 146,972 |
No | output | 1 | 73,486 | 10 | 146,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
import sys
input = sys.stdin.buffer.readline
import bisect
def bisearch(X, Y, Z):
Ys = set(Y)
Zs = set(Z)
Y_ = [-10**9] + Y + [10**9+1]
Z_ = [-10**9] + Z + [10**9+1]
res = 10**30
for x in X:
if x in Ys:
y = x
else:
iy = bisect.bisect_left(Y_, x)-1
y = Y_[iy]
if x in Zs:
z = x
else:
iz = bisect.bisect_right(Z_, x)
z = Z_[iz]
res = min(res, (x-y)**2+(y-z)**2+(z-x)**2)
return res
def main():
t = int(input())
for _ in range(t):
nr, ng, nb = map(int, input().split())
R = list(map(int, input().split()))
G = list(map(int, input().split()))
B = list(map(int, input().split()))
R = list(set(R))
G = list(set(G))
B = list(set(B))
nr = len(R)
ng = len(G)
nb = len(B)
R.sort()
G.sort()
B.sort()
ans = 10**30
ans = min(ans, bisearch(R, G, B))
ans = min(ans, bisearch(R, B, G))
ans = min(ans, bisearch(G, R, B))
ans = min(ans, bisearch(G, B, R))
ans = min(ans, bisearch(B, G, R))
ans = min(ans, bisearch(B, R, G))
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 73,487 | 10 | 146,974 |
No | output | 1 | 73,487 | 10 | 146,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
from sys import stdin
input = stdin.readline
if __name__ == '__main__':
for _ in range(int(input())):
nr, ng, nb = map(int, input().split())
rarr = list(map(int, input().split()))
garr = list(map(int, input().split()))
barr = list(map(int, input().split()))
rarr.sort()
garr.sort()
barr.sort()
t0 = (0, rarr, rarr[0])
t1 = (0, garr, garr[0])
t2 = (0, barr, barr[0])
x = t0[2]
y = t1[2]
z = t2[2]
md = (x - y) ** 2 + (x - z) ** 2 + (y - z) ** 2
while t0[0] + 1 < len(t0[1]) or t1[0] + 1 < len(t1[1]) or t2[0] + 1 < len(t2[1]):
x = t0[2]
y = t1[2]
z = t2[2]
d = (x - y) ** 2 + (x - z) ** 2 + (y - z) ** 2
md = min(md, d)
s = sorted([t0, t1, t2], key=lambda x: x[2])
t0 = s[0]
t1 = s[1]
t2 = s[2]
if t0[0] + 1 < len(t0[1]):
t0 = (t0[0] + 1, t0[1], t0[1][t0[0] + 1])
elif t1[0] + 1 < len(t1[1]):
t1 = (t1[0] + 1, t1[1], t1[1][t1[0] + 1])
else:
t2 = (t2[0] + 1, t2[1], t2[1][t2[0] + 1])
print(md)
``` | instruction | 0 | 73,488 | 10 | 146,976 |
No | output | 1 | 73,488 | 10 | 146,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
###########################################################################
from bisect import bisect
t=int(input())
for i in range(t):
r,g,b=map(int,input().split())
ans=3*(10**18)
l=[]
lr=list(map(int,input().split()))
lg=list(map(int,input().split()))
lb=list(map(int,input().split()))
lr.sort()
lg.sort()
lb.sort()
for i in lr:
a=bisect(lb,i)
if a!=0 and a!=b:
x=lb[a-1]
y=lb[a]
elif a==0:
x=lb[a]
y=lb[a]
else:
x=lb[a-1]
y=lb[a-1]
p=(i+x)//2
q=(i+y)//2
a=bisect(lg,p)
if a!=0 and a!=g:
if p-lg[a-1]>lg[a]-p:
z=lg[a]
else:
z=lg[a-1]
elif a==0:
z=lg[a]
else:
z=lg[a-1]
ans1=(i-z)**2+(z-x)**2+(i-x)**2
a=bisect(lg,q)
if a!=0 and a!=g:
if q-lg[a-1]>lg[a]-q:
z=lg[a]
else:
z=lg[a-1]
elif a==0:
z=lg[a]
else:
z=lg[a-1]
ans2=(i-z)**2+(z-y)**2+(i-y)**2
ans=min(ans,min(ans1,ans2))
print(ans)
``` | instruction | 0 | 73,489 | 10 | 146,978 |
No | output | 1 | 73,489 | 10 | 146,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.
Input
Input will begin with an integer n (1 β€ n β€ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109.
Output
Print the minimum cost to acquire all the pies.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
6
3 4 5 3 4 5
Output
14
Input
5
5 5 5 5 5
Output
25
Input
4
309999 6000 2080 2080
Output
314159
Note
In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free.
In the second test case you have to pay full price for every pie. | instruction | 0 | 73,637 | 10 | 147,274 |
Tags: dp, greedy
Correct Solution:
```
#https://codeforces.com/problemset/problem/335/F
h = [i for i in range(500001)]
t = [i for i in range(500001)]
ans = 0
len = 0
nw = 0
tot = 0
cnt = 0
a = []
def work(x):
y = x >> 1
while y and h[y] > h[x]:
tmp = h[x]
h[x] = h[y]
h[y] = tmp
x = y
y = x >> 1
def pop():
global len
h[1] = h[len]
len -= 1
x = 1
y = 2
if y < len and h[y + 1] < h[y]:
y += 1
while y <= len and h[y] < h[x]:
tmp = h[x]
h[x] = h[y]
h[y] = tmp
x = y
y = x << 1
if y < len and h[y + 1] < h[y]:
y += 1
def solve():
global cnt, len, tot, nw, a
n = int(input())
a = list(map(int, input().split()))
# print(a)
ans = sum(a)
a.sort(reverse = True)
a.insert(0, -1)
# print(a)
for i in range(1, n + 1):
if not nw:
nw = a[i]
tot = 1
else:
if nw > a[i]:
tot -= 1
cnt += 1
t[cnt] = a[i]
if not tot:
nw = 0
else:
tot += 1
if tot >= 2 and len and h[1] < a[i] * 2:
if h[1] < a[i]:
cnt += 1
t[cnt] = a[i]
cnt += 1
t[cnt] = a[i]
else:
cnt += 1
t[cnt] = h[1]
cnt += 1
t[cnt] = a[i] * 2 - h[1]
pop()
tot -= 2
if not tot:
nw = 0
if i == n or a[i + 1] != a[i]:
if nw == a[i] and len and h[1] < a[i]:
pop()
cnt += 1
t[cnt] = a[i]
for j in range(1, cnt + 1):
len += 1
h[len] = t[j]
work(len)
cnt = 0
for i in range(1, len + 1):
ans -= h[i]
print(ans)
solve()
``` | output | 1 | 73,637 | 10 | 147,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.
Input
Input will begin with an integer n (1 β€ n β€ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109.
Output
Print the minimum cost to acquire all the pies.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
6
3 4 5 3 4 5
Output
14
Input
5
5 5 5 5 5
Output
25
Input
4
309999 6000 2080 2080
Output
314159
Note
In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free.
In the second test case you have to pay full price for every pie.
Submitted Solution:
```
'''
Created on 2013-8-7
@author: Zensiu
'''
def min_cost_buy_pies():
n = int(input())
a = input().strip().split(' ')
p = []
for i in a:
p.append(int(i))
if n != len(p):
print("wrong number of prices")
p.sort(reverse=True)
'''
Solution 1, failed
'''
# while p:
# print(p[0])
# print(p)
## for j in p[1:]:
## if p[0] > j:
## min += p[0]
## p.pop(0)
## p.remove(j)
## break
# j = iter(p)
# try:
# while True:
# k = next(j)
# if p[0] > k:
# p.remove(k)
# break
# except StopIteration:
# pass
# min += p[0]
# p.pop(0)
opt = []
for i in range(1, len(p)//2 + 1):
l1 = p[:i]
l2 = p[i:]
# print(l1)
# print(l2)
compare_lists(l1, l2)
# print(l1)
# print(l2)
opt.append(sum(l1)+sum(l2))
opt.sort()
print(opt[0])
def compare_lists(l1, l2):
is_all = True
for j in range(0, min(len(l1), len(l2))):
if l1[j] > l2[j]:
l2[j] = 0
is_all *= True
else:
l2.insert(j, 0)
is_all = False
if is_all == True:
return
compare_lists(l1, l2)
if __name__ == "__main__":
min_cost_buy_pies()
``` | instruction | 0 | 73,638 | 10 | 147,276 |
No | output | 1 | 73,638 | 10 | 147,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.
Input
Input will begin with an integer n (1 β€ n β€ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109.
Output
Print the minimum cost to acquire all the pies.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
6
3 4 5 3 4 5
Output
14
Input
5
5 5 5 5 5
Output
25
Input
4
309999 6000 2080 2080
Output
314159
Note
In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free.
In the second test case you have to pay full price for every pie.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
pie = 0
for i in range(n-1):
if l[i] > l[i+1]:
pie += l[i]
l[i+1] = 0
else:
pie += l[i]
if l[-1] != 0 and len(l)%2 != 0:
pie += l[-1]
print(pie)
``` | instruction | 0 | 73,639 | 10 | 147,278 |
No | output | 1 | 73,639 | 10 | 147,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.
Input
Input will begin with an integer n (1 β€ n β€ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109.
Output
Print the minimum cost to acquire all the pies.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
6
3 4 5 3 4 5
Output
14
Input
5
5 5 5 5 5
Output
25
Input
4
309999 6000 2080 2080
Output
314159
Note
In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free.
In the second test case you have to pay full price for every pie.
Submitted Solution:
```
#!/usr/bin/env python
import os
def index_of_unique(n, data):
c = 0
last = -1
for d in range(len(data)):
if data[d] != data[last]:
last = d
c += 1
if n == c:
break
if n != c:
return -1
else:
return last
def main():
# Take care of input.
data = input()
# Listify.
data = data.split(' ')
# Numberfy.
data = list(map(int, data))
# Sortify.
data = sorted(data)
total = 0
print("orig " + str(data))
# Take care of odd lists.
if len(data) % 2 != 0:
print("odd list")
total += data.pop(0)
last = -1
while index_of_unique(2, data) != -1:
i = 0
for i in range(len(data)):
if data[i] > last:
last = data[i]
if last == max(data):
i = 0
last = data[0]
print("reset to " + str(last))
break
print("throw " + str(data.pop(i)))
print("now " + str(data))
for i in range(len(data)):
if data[i] > last:
break
to_sum = data.pop(i)
print("sum " + str(to_sum))
total += to_sum
print("now " + str(data))
print("len " + str(last))
total += sum(data)
print("total " + str(total))
main()
``` | instruction | 0 | 73,640 | 10 | 147,280 |
No | output | 1 | 73,640 | 10 | 147,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.
Input
Input will begin with an integer n (1 β€ n β€ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109.
Output
Print the minimum cost to acquire all the pies.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
6
3 4 5 3 4 5
Output
14
Input
5
5 5 5 5 5
Output
25
Input
4
309999 6000 2080 2080
Output
314159
Note
In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free.
In the second test case you have to pay full price for every pie.
Submitted Solution:
```
#https://codeforces.com/problemset/problem/335/F
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
cost = 0
for i in range(n-1):
if l[i] > l[i+1]:
cost += l[i]
l[i+1] = 0
else:
cost += l[i]
if l[-1] != 0 and len(l)%2 != 0:
cost += l[-1]
print(cost)
``` | instruction | 0 | 73,641 | 10 | 147,282 |
No | output | 1 | 73,641 | 10 | 147,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,808 | 10 | 147,616 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
k=0
for i in range(n):
if l[i]>k :
k=l[i]
s=0
for i in range(n):
s=s+(k-l[i])
print(s)
``` | output | 1 | 73,808 | 10 | 147,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,809 | 10 | 147,618 |
Tags: implementation, math
Correct Solution:
```
n=int (input())
t=list(map(int,input().split()))
m=max(t)
c=0
for i in t:
c+=m-i
print(c)
``` | output | 1 | 73,809 | 10 | 147,619 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,810 | 10 | 147,620 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
l=list(map(int,input().split(" ")))
l=sorted(l)
a=l[-1]
l.remove(l[-1])
if(n==1):
print("0")
else:
sum=0
for i in l:
sum+=(a-i)
print(sum)
``` | output | 1 | 73,810 | 10 | 147,621 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,811 | 10 | 147,622 |
Tags: implementation, math
Correct Solution:
```
NUM_CASES = input()
INTS = [int(n) for n in input().split()]
MAX = max(INTS) if INTS else 0
def diff (x):
return MAX - x
INTS = [diff(x) for x in INTS]
TOTAL = sum(INTS)
print(TOTAL)
``` | output | 1 | 73,811 | 10 | 147,623 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,812 | 10 | 147,624 |
Tags: implementation, math
Correct Solution:
```
a=int(input())
s=list(map(int,input().split()))
ma=max(s)
count=0
for i in s:
if i<ma:
count=count+ma-i
print(count)
``` | output | 1 | 73,812 | 10 | 147,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,813 | 10 | 147,626 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
l=[int(i) for i in input().split()]
k=max(l)
cnt=0
for i in l:
cnt=cnt+k-i
print(cnt)
``` | output | 1 | 73,813 | 10 | 147,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,814 | 10 | 147,628 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
d = max(a)
c = 0
for i in a:
s = d-i
c +=s
print(c)
``` | output | 1 | 73,814 | 10 | 147,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | instruction | 0 | 73,815 | 10 | 147,630 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
s = list(map(int,input().split()))
print((n*max(s))-sum(s))
``` | output | 1 | 73,815 | 10 | 147,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
Submitted Solution:
```
n=int(input())
li=[int (num) for num in input().split(" ",n-1)]
li.sort()
tk=0
for i in range(len(li)):
tk+=max(li)-li[i]
print(tk)
``` | instruction | 0 | 73,816 | 10 | 147,632 |
Yes | output | 1 | 73,816 | 10 | 147,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
Submitted Solution:
```
input()
wealth=list(map(int,input().split(' ')))
desired=max(wealth)
needed=0
for i in wealth:
needed+=int(desired)-int(i)
print(needed)
``` | instruction | 0 | 73,817 | 10 | 147,634 |
Yes | output | 1 | 73,817 | 10 | 147,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
Submitted Solution:
```
# cook your dish here
n=int(input())
li=list(map(int,input().split(" ")))
m=max(li)
s=0
for i in li:
s+=m-i
print(s)
``` | instruction | 0 | 73,818 | 10 | 147,636 |
Yes | output | 1 | 73,818 | 10 | 147,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
Submitted Solution:
```
a=int(input())
b=list(map(int,input().split()))
c=max(b)
z=0
for i in range(0,len(b)):
i=b[i]
m=c-i
z+=m
print(z)
``` | instruction | 0 | 73,819 | 10 | 147,638 |
Yes | output | 1 | 73,819 | 10 | 147,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input
The first line contains the integer n (1 β€ n β€ 100) β the number of citizens in the kingdom.
The second line contains n integers a1, a2, ..., an, where ai (0 β€ ai β€ 106) β the welfare of the i-th citizen.
Output
In the only line print the integer S β the minimum number of burles which are had to spend.
Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
Submitted Solution:
```
x = list(map(int,input().split()))
maxx = max(x)
summ = 0
for i in x: summ += maxx - i
print(maxx)
``` | instruction | 0 | 73,820 | 10 | 147,640 |
No | output | 1 | 73,820 | 10 | 147,641 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.