message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.
When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.
Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".
Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Constraints
* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Examples
Input
3
10 10
20 20
30 30
Output
20
Input
3
20 10
20 20
20 30
Output
20
Input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
-2999999997
Submitted Solution:
```
n=int(input())
l=[None]*n
for i in range(n):
a,b=map(int,input().split())
l[i]=[a,b]
l.sort(key=lambda x:x[0]+x[1], reverse=True)
#print(l)
ans=0
for i in range(n):
if i%2:
ans-=l[i][1]
else:
ans+=l[i][0]
print(ans)
``` | instruction | 0 | 101,866 | 9 | 203,732 |
Yes | output | 1 | 101,866 | 9 | 203,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.
When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.
Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".
Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Constraints
* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Examples
Input
3
10 10
20 20
30 30
Output
20
Input
3
20 10
20 20
20 30
Output
20
Input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
-2999999997
Submitted Solution:
```
N = int(input())
AB = [0 for _ in range(N)]
SB = 0
for i in range(N):
A, B = map(int, input().split())
SB += B
AB[i] = A + B
AB.sort(reverse=True)
SAB = 0
for i in range(N):
if i % 2 == 0:
SAB += AB[i]
print(SAB-SB)
``` | instruction | 0 | 101,867 | 9 | 203,734 |
Yes | output | 1 | 101,867 | 9 | 203,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.
When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.
Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".
Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Constraints
* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Examples
Input
3
10 10
20 20
30 30
Output
20
Input
3
20 10
20 20
20 30
Output
20
Input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
-2999999997
Submitted Solution:
```
n = int(input())
taka = []
aoki = []
score = 0
for i in range(n):
t, a = map(int, input().split())
taka.append(t)
aoki.append(a)
for i in range(n):
maxT = max(taka)
maxA = max(aoki)
rm = 0
if (maxT > maxA):
rm = taka.index(maxT)
else:
rm = aoki.index(maxA)
if (i % 2 == 0):
score += taka.pop(rm)
aoki.pop(rm)
else:
taka.pop(rm)
score -= aoki.pop(rm)
print(score)
``` | instruction | 0 | 101,868 | 9 | 203,736 |
No | output | 1 | 101,868 | 9 | 203,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.
When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.
Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".
Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Constraints
* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Examples
Input
3
10 10
20 20
30 30
Output
20
Input
3
20 10
20 20
20 30
Output
20
Input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
-2999999997
Submitted Solution:
```
#coding:utf-8
###### input ######
n = int(input())
taka = []
aoki = []
for i in range(n):
t,a= map(int,input().split())
taka.append(t)
aoki.append(a)
###### main ######
res = 0
for i in range(n):
if i % 2 == 0: # turn TAKAHASHI
if max(taka) < max(aoki):
tmp = aoki.index(max(aoki))#[0]
else:
tmp = taka.index(max(taka))#[0]
print(tmp)
res+= taka[tmp]
taka[tmp] = 0
aoki[tmp] = 0
else:
if max(taka) > max(aoki):
tmp = taka.index(max(taka))#[0]
else:
tmp = aoki.index(max(aoki))#[0]
print(tmp)
res -= aoki[tmp]
taka[tmp] = 0
aoki[tmp] = 0
print(res)
``` | instruction | 0 | 101,869 | 9 | 203,738 |
No | output | 1 | 101,869 | 9 | 203,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.
When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.
Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".
Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Constraints
* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Examples
Input
3
10 10
20 20
30 30
Output
20
Input
3
20 10
20 20
20 30
Output
20
Input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
-2999999997
Submitted Solution:
```
n = int(input())
for i in range(n):
ab[i][0], ab[i][1] = map(int, input().split())
ab[i][2] = ab[i][0] + ab[i][1]
sorted(ab, key=lambda x: x[2])
print(sum(ab[0::2][0])-sum(ab[1::2][1]))
``` | instruction | 0 | 101,870 | 9 | 203,740 |
No | output | 1 | 101,870 | 9 | 203,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.
When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness.
Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".
Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Constraints
* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
Examples
Input
3
10 10
20 20
30 30
Output
20
Input
3
20 10
20 20
20 30
Output
20
Input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
Output
-2999999997
Submitted Solution:
```
def solve(n, xs, ys):
first_score = 0
second_score = 0
zs = sorted(zip(xs, ys))
for i in range(n):
if i % 2 == 0:
first_score += zs[i][0]
else:
second_score += zs[i][1]
res = first_score - second_score
return res
def main():
n = int(input())
xs = [0] * n
ys = [0] * n
for i in range(n):
xs[i], ys[i] = (int(z) for z in input().split())
res = solve(n, xs, ys)
print(res)
if __name__ == "__main__":
main()
``` | instruction | 0 | 101,871 | 9 | 203,742 |
No | output | 1 | 101,871 | 9 | 203,743 |
Provide a correct Python 3 solution for this coding contest problem.
Problem Statement
You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as many different restaurants as possible in the night. He doesn't have plenty of time tonight, however, because he has to get up early in the morning tomorrow to join a training session. So he asked you to find the maximum number of different restaurants to which he would be able to go to eat ramen in the limited time.
There are $n$ railway stations in the city, which are numbered $1$ through $n$. The station $s$ is the nearest to the camp venue. $m$ pairs of stations are directly connected by the railway: you can move between the stations $a_i$ and $b_i$ in $c_i$ minutes in the both directions. Among the stations, there are $l$ stations where a SIRO restaurant is located nearby. There is at most one SIRO restaurant around each of the stations, and there are no restaurants near the station $s$. It takes $e_i$ minutes for Jiro to eat ramen at the restaurant near the station $j_i$.
It takes only a negligibly short time to go back and forth between a station and its nearby SIRO restaurant. You can also assume that Jiro doesn't have to wait for the ramen to be served in the restaurants.
Jiro is now at the station $s$ and have to come back to the station in $t$ minutes. How many different SIRO's can he taste?
Input
The input is a sequence of datasets. The number of the datasets does not exceed $100$. Each dataset is formatted as follows:
> $n$ $m$ $l$ $s$ $t$
> $a_1$ $b_1$ $c_1$
> :
> :
> $a_m$ $b_m$ $c_m$
> $j_1$ $e_1$
> :
> :
> $j_l$ $e_l$
The first line of each dataset contains five integers:
* $n$ for the number of stations,
* $m$ for the number of directly connected pairs of stations,
* $l$ for the number of SIRO restaurants,
* $s$ for the starting-point station, and
* $t$ for the time limit for Jiro.
Each of the following $m$ lines contains three integers:
* $a_i$ and $b_i$ for the connected stations, and
* $c_i$ for the time it takes to move between the two stations.
Each of the following $l$ lines contains two integers:
* $j_i$ for the station where a SIRO restaurant is located, and
* $e_i$ for the time it takes for Jiro to eat at the restaurant.
The end of the input is indicated by a line with five zeros, which is not included in the datasets.
The datasets satisfy the following constraints:
* $2 \le n \le 300$
* $1 \le m \le 5{,}000$
* $1 \le l \le 16$
* $1 \le s \le n$
* $1 \le t \le 100{,}000$
* $1 \le a_i, b_i \le n$
* $1 \le c_i \le 1{,}000$
* $1 \le j_i \le n$
* $1 \le e_i \le 15$
* $s \ne j_i$
* $j_i$'s are distinct.
* $a_i \ne b_i$
* $(a_i, b_i) \ne (a_j, b_j)$ and $(a_i, b_i) \ne (b_j, a_j)$ for any $i \ne j$
Note that there may be some stations not reachable from the starting point $s$.
Output
For each data set, output the maximum number of different restaurants where Jiro can go within the time limit.
Sample Input
2 1 1 1 10
1 2 3
2 4
2 1 1 1 9
1 2 3
2 4
4 2 2 4 50
1 2 5
3 4 5
2 15
3 15
4 6 3 1 29
1 2 20
3 2 10
4 1 5
3 1 5
2 4 3
3 4 4
2 1
4 5
3 3
0 0 0 0 0
Output for the Sample Input
1
0
1
3
Example
Input
2 1 1 1 10
1 2 3
2 4
2 1 1 1 9
1 2 3
2 4
4 2 2 4 50
1 2 5
3 4 5
2 15
3 15
4 6 3 1 29
1 2 20
3 2 10
4 1 5
3 1 5
2 4 3
3 4 4
2 1
4 5
3 3
0 0 0 0 0
Output
1
0
1
3 | instruction | 0 | 102,852 | 9 | 205,704 |
"Correct Solution:
```
from heapq import heappush, heappop
import sys
def main():
readline = sys.stdin.readline
write = sys.stdout.write
L2 = 1 << 16
bc = [0]*L2
for i in range(1, L2):
bc[i] = bc[i ^ (i & -i)] + 1
INF = 10**18
def solve():
N, M, L, s, T = map(int, readline().split())
if N == M == 0:
return False
G = [[] for i in range(N)]
for i in range(M):
a, b, c = map(int, readline().split()); a -= 1; b -= 1
G[a].append((b, c))
G[b].append((a, c))
def dijkstra(s):
dist = [INF]*N
dist[s] = 0
que = [(0, s)]
while que:
cost, v = heappop(que)
if dist[v] < cost:
continue
for w, d in G[v]:
if cost + d < dist[w]:
dist[w] = cost + d
heappush(que, (cost + d, w))
return dist
G0 = [[] for i in range(L)]
RS = []
BS = [0]*L
for i in range(L):
j, e = map(int, readline().split()); j -= 1
d0 = dijkstra(j)
for k, p in enumerate(RS):
v = d0[p]
if v+BS[k] <= T:
G0[i].append((k, v+BS[k], 1 << k))
if v+e <= T:
G0[k].append((i, v+e, 1 << i))
RS.append(j)
BS[i] = e
ans = 0
ds = dijkstra(s-1)
que = []
Q = [[{} for j in range(L)] for i in range(L+1)]
L2 = 1 << L
dw = [0]*L
for i in range(L):
d = ds[RS[i]]
r = d + BS[i]
dw[i] = T - d + 1
if r < dw[i]:
Q[1][i][1 << i] = r
ans = 1
for k in range(1, L):
qs = Q[k]
qs1 = Q[k+1]
if any(qs):
ans = k
for v in range(L):
qsv = qs[v]
for w, d, b in G0[v]:
dww = dw[w]
qs1w = qs1[w]
for state, cost in qsv.items():
if state & b:
continue
r = cost + d
if r < qs1w.get(state | b, dww):
qs1w[state | b] = r
if any(Q[L]):
ans = L
write("%d\n" % ans)
return True
while solve():
...
main()
``` | output | 1 | 102,852 | 9 | 205,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,175 | 9 | 206,350 |
Tags: math
Correct Solution:
```
def genPrimes(n):
sieve = [True]*(n+1)
p = 2
while p*p <= n:
if sieve[p]:
for i in range(p*p, n+1, p):
sieve[i] = False
p += 1
primes = []
for i in range(2, n+1):
if sieve[i]:
primes.append(i)
return primes
primes = genPrimes(2000000)
n = int(input().strip())
print(*primes[:n])
``` | output | 1 | 103,175 | 9 | 206,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,176 | 9 | 206,352 |
Tags: math
Correct Solution:
```
n = int(input())
for i in range(n):
print((3*n)+i, end='\t')
``` | output | 1 | 103,176 | 9 | 206,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,177 | 9 | 206,354 |
Tags: math
Correct Solution:
```
def print_first_N_primes(n):
start = 9000001
temp = start
for i in range(start,start+n):
print(i,end=" ")
num = int(input())
print_first_N_primes(num)
print("")
``` | output | 1 | 103,177 | 9 | 206,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,178 | 9 | 206,356 |
Tags: math
Correct Solution:
```
import sys
n = int(input())
for i in range(10000000-n, 9999999):
sys.stdout.write(str(i) + " ")
sys.stdout.write("9999999")
``` | output | 1 | 103,178 | 9 | 206,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,179 | 9 | 206,358 |
Tags: math
Correct Solution:
```
n=int(input())
for i in range(100000,100000+n):
print(i,end=" ")
``` | output | 1 | 103,179 | 9 | 206,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,180 | 9 | 206,360 |
Tags: math
Correct Solution:
```
n = int(input())
a = 1000000
for i in range(n):
print(a, end = " ")
a += 1
``` | output | 1 | 103,180 | 9 | 206,361 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,181 | 9 | 206,362 |
Tags: math
Correct Solution:
```
len = int(input())
for i in range(0, len):
print(len*2+i, end=' ')
``` | output | 1 | 103,181 | 9 | 206,363 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31 | instruction | 0 | 103,182 | 9 | 206,364 |
Tags: math
Correct Solution:
```
n=int(input())
y=0
a=[3*n]
while(len(a)!=n):
a.append(a[-1]+1)
if(len(a)>n):
a.pop()
for i in a:
print(i,end=" ")
print()
``` | output | 1 | 103,182 | 9 | 206,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
n = int(input())
for i in range(n) :
print(5*n + i, end = " ")
``` | instruction | 0 | 103,183 | 9 | 206,366 |
Yes | output | 1 | 103,183 | 9 | 206,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
n = int(input())
for i in range(n):
print(100000+i, end=' ')
print('')
``` | instruction | 0 | 103,184 | 9 | 206,368 |
Yes | output | 1 | 103,184 | 9 | 206,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/327/B
n = int(input())
for i in range(n):
print(3 * n + i, end = " ")
``` | instruction | 0 | 103,185 | 9 | 206,370 |
Yes | output | 1 | 103,185 | 9 | 206,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
import sys
#f = sys.stdin
#f = open("input.txt", "r")
n = int(input())
# a = [2]
# k = 3
# for i in range(1, n):
# a.append(a[i-1] + 1)
# j = 0
# while j < i:
# if a[i]%a[j] == 0:
# a[i] += 1
# j = 0
# else:
# j += 1
# print(a[i])
# print(" ".join(map(str, a)))
for i in range(n, n+n):
print(i, end=" ")
``` | instruction | 0 | 103,186 | 9 | 206,372 |
Yes | output | 1 | 103,186 | 9 | 206,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
from functools import reduce
ans = [3, 5]
n = int(input())
for i in range(n):
flag = reduce(lambda a, b:a*b + 1, ans)
ans.append(flag)
print(*ans[:n])
``` | instruction | 0 | 103,187 | 9 | 206,374 |
No | output | 1 | 103,187 | 9 | 206,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
#!/usr/bin/env python
# coding: utf-8
# In[204]:
# # n = int(input())
# # line = list(map(int, input().split()))
# # line = list(str(input()))
# In[224]:
import math
# In[213]:
n = int(input())
# In[ ]:
# In[233]:
# est_upper = n * 6
sqrt_val = round(math.sqrt(n * 10))
not_prime = [i * j for j in range(2, sqrt_val) for i in range(2, sqrt_val)]
# In[234]:
count = 0
res = []
for i in range(len(not_prime)-1):
if count >= n:
break
a = not_prime[i+1]
b = not_prime[i]
if a - b > 1:
for j in range(b+1, a):
res.append(str(j))
count += 1
if count >= n:
break
print(" ".join(res))
# In[171]:
# count = 0
# c = 0
# for i in range(2, est_upper):
# c += 1
# if count >= n:
# break
# if i not in not_prime:
# # print(i, end = " ")
# count += 1
# print(c)
# In[146]:
# count = 0
# for i in range(2, 1420):
# for j in range(2, 1420):
# val = i*j
# if val < 2000000:
# prime[val] = False
# In[135]:
# prime = [True] * 2000000
# flag = 0
# for i in range(2, 1410):
# for j in range(2, 1410):
# if i*j > 500000:
# flag = 1
# break
# prime[i*j] = False
# if flag:
# break
# In[147]:
# count = 0
# print(2, end = ' ')
# for i in range(3, 5000000):
# if count >= n - 1:
# break
# if prime[i] == True:
# print(i, end = ' ')
# count += 1
# # print(" ".join(res))
# In[ ]:
# In[ ]:
``` | instruction | 0 | 103,188 | 9 | 206,376 |
No | output | 1 | 103,188 | 9 | 206,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
a = int(input())
v,w = [],(a//2)+1
for i in range(1,(a//2)+1):
v.append((6*i)-1)
v.append((6*i)+1)
if a%2!=0:
v.append((6*w)-1)
print(*v)
``` | instruction | 0 | 103,189 | 9 | 206,378 |
No | output | 1 | 103,189 | 9 | 206,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
* Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
* For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
Input
The input contains a single integer: n (1 β€ n β€ 105).
Output
Output a line that contains n space-separated integers a1 a2, ..., an (1 β€ ai β€ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Examples
Input
3
Output
2 9 15
Input
5
Output
11 14 20 27 31
Submitted Solution:
```
n=int(input())
if(n==1):
print(1)
else:
print(5,end=" ")
i=1
while(i<n):
print('1'*(i+1),end=" ")
i+=1
``` | instruction | 0 | 103,190 | 9 | 206,380 |
No | output | 1 | 103,190 | 9 | 206,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,294 | 9 | 206,588 |
Tags: greedy
Correct Solution:
```
import sys
import math
input = sys.stdin.readline
def int_array():
return list(map(int, input().strip().split()))
def str_array():
return input().strip().split()
price = []
day = []
mini = 10e56
count = 0
n = int(input());
for _ in range(n):
days, cost = int_array()
price.append(cost)
day.append(days)
for i in range(n):
if price[i] < mini:
mini = price[i]
count += day[i]*mini
print(count)
``` | output | 1 | 103,294 | 9 | 206,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,295 | 9 | 206,590 |
Tags: greedy
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
answer = 0
m = inf
for _ in range(int(data())):
a, p = sp()
m = min(m, p)
answer += a * m
out(answer)
``` | output | 1 | 103,295 | 9 | 206,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,296 | 9 | 206,592 |
Tags: greedy
Correct Solution:
```
n = int(input())
s = [[int(x)for x in input().split()]for i in range(n)]
amount, price = s[0][0], s[0][1]
cost = amount * price
for i in range(1,n):
amount = s[i][0]
if s[i][1] < price:
price = s[i][1]
cost += amount * price
print(cost)
``` | output | 1 | 103,296 | 9 | 206,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,297 | 9 | 206,594 |
Tags: greedy
Correct Solution:
```
# https://codeforces.com/contest/588/problem/A
def single_integer():
return int(input())
def multi_integer():
return map(int, input().split())
def string():
return input()
def multi_string():
return input().split()
n = single_integer()
ans = 0
previous = float('inf')
for i in range(1, n + 1):
a, p = multi_integer()
if p > previous:
ans += a * previous
else:
ans += a * p
previous = p
print(ans)
``` | output | 1 | 103,297 | 9 | 206,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,298 | 9 | 206,596 |
Tags: greedy
Correct Solution:
```
mn=10**9
res=0
for n in range(int(input())):
a,b=map(int,input().split())
if b<=mn:
mn=b
res+=a*mn
print(res)
``` | output | 1 | 103,298 | 9 | 206,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,299 | 9 | 206,598 |
Tags: greedy
Correct Solution:
```
n = int(input())
MIN = 101
res = 0
for i in range(n):
a, p = input().split()
a, p = int(a), int(p)
MIN = min(p, MIN)
res += MIN * a
print(res)
``` | output | 1 | 103,299 | 9 | 206,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,300 | 9 | 206,600 |
Tags: greedy
Correct Solution:
```
n = int(input())
res,cost = 0,2e9
for i in range(n):
a,b = map(int,input().split(' '))
if(b < cost):
cost = b
res+=a*cost
print(res)
``` | output | 1 | 103,300 | 9 | 206,601 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | instruction | 0 | 103,301 | 9 | 206,602 |
Tags: greedy
Correct Solution:
```
n = int(input())
price = 10000
sum = 0
for i in range(n):
a, b = [int(a) for a in input().split()]
if price > b:
price = b
sum += price*a
print(sum)
``` | output | 1 | 103,301 | 9 | 206,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
n = int(input())
a, p = [0]*n, [0]*n
for i in range(n):
a[i], p[i] = [int(x) for x in input().split()]
curr_min = p[0]
cost = a[0] * p[0]
for i in range(1, n):
if p[i] < curr_min:
curr_min = p[i]
cost += a[i] * curr_min
print(cost)
``` | instruction | 0 | 103,302 | 9 | 206,604 |
Yes | output | 1 | 103,302 | 9 | 206,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
j = l[0][1]
price = 0
for i in range(n-1):
if j < l[i+1][1]:
price += j*l[i][0]
else:
price += j*l[i][0]
j = l[i+1][1]
print(price+j*l[-1][0])
``` | instruction | 0 | 103,303 | 9 | 206,606 |
Yes | output | 1 | 103,303 | 9 | 206,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
n = int(input())
prices = []
amounts = []
min_price = 1000000
for _ in range(n):
a, p = map(int, input().split())
if p < min_price:
prices.append(p)
amounts.append(a)
min_price = p
else:
amounts[-1] += a
print(sum([a * p for a, p in zip(amounts, prices)]))
``` | instruction | 0 | 103,304 | 9 | 206,608 |
Yes | output | 1 | 103,304 | 9 | 206,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
#588A Tutorial
n = int(input())
ans = 0
mn = 200
for i in range(n):
a, p = map(int, input().split())
mn = min(mn, p)
ans += a * mn
print(ans)
``` | instruction | 0 | 103,305 | 9 | 206,610 |
Yes | output | 1 | 103,305 | 9 | 206,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
n = int(input())
x, y = [*map(int, input().split())]
minp = y
ans = x * y
for i in range(n - 1):
if minp > y:
minp = y
ans += x * minp
x, y = [*map(int, input().split())]
print(ans)
``` | instruction | 0 | 103,306 | 9 | 206,612 |
No | output | 1 | 103,306 | 9 | 206,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
__author__ = 'cmashinho'
n = int(input())
needMeat = []
meatPrice = []
for _ in range(n):
a, b = map(int, input().split())
needMeat.append(a)
meatPrice.append(b)
answer = 0
minPrice = min(meatPrice)
for i in range(n):
if i == 0:
if meatPrice[i] == minPrice:
answer += sum(needMeat) * meatPrice[i]
break
answer += needMeat[i] * meatPrice[i]
else:
if meatPrice[i] == minPrice:
for j in range(i, n):
answer += needMeat[j] * minPrice
break
else:
answer += needMeat[i] * meatPrice[i]
print(answer)
``` | instruction | 0 | 103,307 | 9 | 206,614 |
No | output | 1 | 103,307 | 9 | 206,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
n = int(input())
minimun = float("Inf")
money = 0
for i in range(0, n):
amountMeat, price = [int(x) for x in input().split()]
if price < minimun:
minimun = price
money += minimun * amountMeat
``` | instruction | 0 | 103,308 | 9 | 206,616 |
No | output | 1 | 103,308 | 9 | 206,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.
<image>
There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.
Input
The first line of input contains integer n (1 β€ n β€ 105), the number of days.
In the next n lines, i-th line contains two integers ai and pi (1 β€ ai, pi β€ 100), the amount of meat Duff needs and the cost of meat in that day.
Output
Print the minimum money needed to keep Duff happy for n days, in one line.
Examples
Input
3
1 3
2 2
3 1
Output
10
Input
3
1 3
2 1
3 2
Output
8
Note
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
Submitted Solution:
```
lst1=[]
lst2=[]
cost=0
for a in range(int(input())):
lst=[int(x) for x in input().split()]
lst1.append(lst[0])
lst2.append(lst[1])
for i in range(len(lst2)):
if lst2[i] == min(lst2):
cost+= sum(lst1[i:])*lst2[i]
break
else:
cost+=lst1[i]*lst2[i]
print(cost)
``` | instruction | 0 | 103,309 | 9 | 206,618 |
No | output | 1 | 103,309 | 9 | 206,619 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,748 | 9 | 207,496 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
n,m = [int(i) for i in input().split()]
boys = sorted([int(i) for i in input().split()],reverse=True)
girls = sorted([int(i) for i in input().split()])
soma = 0
minGirl = girls[0]
impossivel = False
for i in range(len(boys)):
if(minGirl<boys[i]):
impossivel = True
break
soma += m*boys[i]
if(not impossivel):
flag = False
for i in range(len(girls)-1):
if(girls[i] == boys[0]):
flag = True
soma+= girls[i]-boys[0]
if(flag):
soma+=girls[len(girls)-1]-boys[0]
elif(len(boys)>1 and len(girls)>1):
soma+=girls[len(girls)-1]-boys[1]
elif(minGirl != min(boys)):
impossivel = True
if(impossivel):
print(-1)
else:
print(soma)
else:
print(-1)
``` | output | 1 | 103,748 | 9 | 207,497 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,749 | 9 | 207,498 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
n,m =map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1.sort()
l2.sort()
m1=max(l1)
m2=min(l2)
s1=sum(l1)
s2=sum(l2)
if m2<m1:
print(-1)
else:
if l2[0]>l1[n-1]:
print(m*(s1)-l1[n-2]-(m-1)*l1[n-1]+s2)
else:
print(m*(s1)-(m)*l1[n-1]+s2)
``` | output | 1 | 103,749 | 9 | 207,499 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,750 | 9 | 207,500 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
n, m = map(int, input().split())
b = list(map(int, input().split()))
g = list(map(int, input().split()))
mab = max(b)
mig = min(g)
if mab > mig:
print(-1)
exit()
b = sorted(b, reverse=True)
g = sorted(g)
num = 0
j = 0
for i in range(n):
k = 0
l = 1
while j < m and k < m - l and b[i] <= g[j]:
if b[i] == g[j]:
l = 0
num += g[j]
j += 1
k += 1
num += b[i] * (m - k)
print(num)
``` | output | 1 | 103,750 | 9 | 207,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,751 | 9 | 207,502 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
n,m=map(int,input().split())
lisn=list(map(int,input().split()))
lism=list(map(int,input().split()))
lisn.sort()
lism.sort()
if lism[0]<lisn[-1]:
print(-1)
else:
ans=0
if lism[0]==lisn[-1]:
for i in range(len(lisn)-1):
ans+=lisn[i]*(len(lism))
for i in range(len(lism)):
ans+=lism[i]
else:
for i in range(len(lisn)-1):
ans+=lisn[i]*(len(lism))
for i in range(len(lism)):
ans+=lism[i]
ans+=lisn[-1]-lisn[n-2]
print(ans)
``` | output | 1 | 103,751 | 9 | 207,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,752 | 9 | 207,504 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = sorted(list(map(int, input().split())))
if a[-1] > s[0]:
print(-1)
else:
if a[-1] == s[0]:
print(sum(a[:-1])*m+sum(s))
else:
print(sum(a[:-2])*m+a[-2]*(m-1)+sum(s)+a[-1])
``` | output | 1 | 103,752 | 9 | 207,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,753 | 9 | 207,506 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
n, m = map(int, input().split())
b = sorted(list(map(int, input().split())), reverse=True)
g = sorted(list(map(int, input().split())), reverse=True)
j = 0
ans = 0
for j in range(m-1):
if b[0] > g[j]:
print(-1)
exit(0)
ans += g[j]
if b[0] > g[m-1]:
print(-1)
exit(0)
elif b[0] == g[m-1]:
ans += g[m-1]
for i in range(1, n):
ans += b[i]*m
else:
ans += b[0]+g[m-1]
ans += b[1]*(m-1)
for i in range(2, n):
ans += b[i]*m
print(ans)
``` | output | 1 | 103,753 | 9 | 207,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,754 | 9 | 207,508 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
b=[int(k) for k in input().split()]
g=[int(k) for k in input().split()]
if max(b)>min(g):
print(-1)
elif max(b)==min(g):
print(sum(b)*m+sum(g)-max(b)*m)
else:
b.sort()
print(sum(b) * m + sum(g) - max(b) * (m-1)-b[-2])
``` | output | 1 | 103,754 | 9 | 207,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4. | instruction | 0 | 103,755 | 9 | 207,510 |
Tags: binary search, constructive algorithms, greedy, implementation, math, sortings, two pointers
Correct Solution:
```
def possible(b, g):
if min(g) > max(b):
return False
return True
def is_valid(b, g):
max(b) >= min(g)
n, m = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
B = sum(b)
ans = B * m
mx = max(b)
if max(b) > min(g):
ans = -1
elif min(g) == max(b):
ans -= max(b)*m
ans += sum(g)
else:
# print("here")
ans -= (max(b) * m)
ans += sum(g)
ans -= g[0]
ans += max(b)
b.remove(max(b))
ans -= max(b)
ans += g[0]
print(ans)
``` | output | 1 | 103,755 | 9 | 207,511 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4.
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
mins = [int(i) for i in input().split()]
maxs = [int(i) for i in input().split()]
temp = mins[:]
temp.sort()
pivot = temp[-1]
pivot2 = temp[-2]
ans = sum(mins)*m
ans += sum(maxs)
ans -= pivot*(m-1) + pivot2
bad = False
# for a in maxs:
# if a < pivot:
# bad = True
q = min(maxs)
if q < pivot:
print(-1)
elif q == pivot:
print(ans +pivot2 - pivot)
else:
print(ans)
``` | instruction | 0 | 103,756 | 9 | 207,512 |
Yes | output | 1 | 103,756 | 9 | 207,513 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4.
Submitted Solution:
```
''' CODED WITH LOVE BY SATYAM KUMAR '''
from sys import stdin, stdout
import cProfile, math
from collections import Counter,defaultdict,deque
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27) # new thread will get stack of such size
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys
class merge_find:
def __init__(self,n):
self.parent = list(range(n))
self.size = [1]*n
self.num_sets = n
self.lista = [[_] for _ in range(n)]
def find(self,a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
self.parent[b] = a
return self.parent[a]
def merge(self,a,b):
a = self.find(a)
b = self.find(b)
if a==b:
return
if self.size[a]<self.size[b]:
a,b = b,a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
self.lista[a] += self.lista[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
def display(string_to_print):
stdout.write(str(string_to_print) + "\n")
def primeFactors(n): #n**0.5 complex
factors = dict()
for i in range(2,math.ceil(math.sqrt(n))+1):
while n % i== 0:
if i in factors:
factors[i]+=1
else: factors[i]=1
n = n // i
if n>2:
factors[n]=1
return (factors)
def all_factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def fibonacci_modP(n,MOD):
if n<2: return 1
#print (n,MOD)
return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD
def factorial_modP_Wilson(n , p):
if (p <= n):
return 0
res = (p - 1)
for i in range (n + 1, p):
res = (res * cached_fn(InverseEuler,i, p)) % p
return res
def binary(n,digits = 20):
b = bin(n)[2:]
b = '0'*(digits-len(b))+b
return b
def isprime(n):
"""Returns True if n is prime."""
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def generate_primes(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n+1, p):
prime[i] = False
p += 1
return prime
factorial_modP = []
def warm_up_fac(MOD):
global factorial_modP,fac_warmup
if fac_warmup: return
factorial_modP= [1 for _ in range(fac_warmup_size+1)]
for i in range(2,fac_warmup_size):
factorial_modP[i]= (factorial_modP[i-1]*i) % MOD
fac_warmup = True
def InverseEuler(n,MOD):
return pow(n,MOD-2,MOD)
def nCr(n, r, MOD):
global fac_warmup,factorial_modP
if not fac_warmup:
warm_up_fac(MOD)
fac_warmup = True
return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD
def test_print(*args):
if testingMode:
print(args)
def display_list(list1, sep=" "):
stdout.write(sep.join(map(str, list1)) + "\n")
def display_2D_list(li):
for i in li:
print(i)
def prefix_sum(li):
sm = 0
res = []
for i in li:
sm+=i
res.append(sm)
return res
def get_int():
return int(stdin.readline().strip())
def get_tuple():
return map(int, stdin.readline().split())
def get_list():
return list(map(int, stdin.readline().split()))
import heapq,itertools
pq = [] # list of entries arranged in a heap
entry_finder = {} # mapping of tasks to entries
REMOVED = '<removed-task>'
def add_task(task, priority=0):
'Add a new task or update the priority of an existing task'
if task in entry_finder:
remove_task(task)
count = next(counter)
entry = [priority, count, task]
entry_finder[task] = entry
heapq.heappush(pq, entry)
def remove_task(task):
'Mark an existing task as REMOVED. Raise KeyError if not found.'
entry = entry_finder.pop(task)
entry[-1] = REMOVED
def pop_task():
'Remove and return the lowest priority task. Raise KeyError if empty.'
while pq:
priority, count, task = heapq.heappop(pq)
if task is not REMOVED:
del entry_finder[task]
return task
raise KeyError('pop from an empty priority queue')
memory = dict()
def clear_cache():
global memory
memory = dict()
def cached_fn(fn, *args):
global memory
if args in memory:
return memory[args]
else:
result = fn(*args)
memory[args] = result
return result
def ncr (n,r):
return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
def binary_serach(i,li):
#print("Search for ",i)
fn = lambda x: li[x]-x//i
x = -1
b = len(li)
while b>=1:
#print(b,x)
while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like
x+=b
b=b//2
return x
# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
fac_warmup_size = 10**5+100
optimiseForReccursion = False #Can not be used clubbed with TestCases # WHen using recursive functions, use Python 3
from math import factorial
def main():
n, m= get_tuple()
boys = get_list()
girls = get_list()
boys.sort(reverse= True)
min_girl = min(girls)
max_boy = boys[0]
res = (sum(boys)-max_boy)*m + sum(girls)
if max_boy<min_girl:
print(res+max_boy-boys[1])
elif max_boy==min_girl:
print(res)
else:
print(-1)
# --------------------------------------------------------------------- END=
if TestCases:
for i in range(get_int()):
cProfile.run('main()') if testingMode else main()
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()
``` | instruction | 0 | 103,757 | 9 | 207,514 |
Yes | output | 1 | 103,757 | 9 | 207,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4.
Submitted Solution:
```
from collections import deque
n, m = map(int, input().split())
b = list(map(int, input().split()))
g = list(map(int, input().split()))
b.sort(reverse = True)
g.sort(reverse = True)
g = deque(g)
if max(b) > min(g):
print(-1)
else:
t = 0
for e in b:
t += e * m
special = len(g) == m and g[-1] >= e
i = 0
while i < len(g) - special and g[0] >= e:
t += g[0] - e
g.popleft()
if special and g[-1] == e:
g.popleft()
print(t)
``` | instruction | 0 | 103,758 | 9 | 207,516 |
Yes | output | 1 | 103,758 | 9 | 207,517 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.