message stringlengths 2 39.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 450 109k | cluster float64 2 2 | __index_level_0__ int64 900 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=1)
print(sum(a[k:]))
``` | instruction | 0 | 84,813 | 2 | 169,626 |
Yes | output | 1 | 84,813 | 2 | 169,627 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
N,K=map(int,input().split())
H=list(map(int,input().split()))
H=sorted(H)[::-1]
print(sum(H[K:]))
``` | instruction | 0 | 84,814 | 2 | 169,628 |
Yes | output | 1 | 84,814 | 2 | 169,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
n,k,*h=map(int,open(0).read().split())
if n<k:
print(0)
else:
h.sort()
h=h[:(n-k)]
print(sum(h))
``` | instruction | 0 | 84,815 | 2 | 169,630 |
Yes | output | 1 | 84,815 | 2 | 169,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
s=sum(l[k:])
print(s)
``` | instruction | 0 | 84,816 | 2 | 169,632 |
Yes | output | 1 | 84,816 | 2 | 169,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
arr = input().split(" ")
N = int(arr[0])
K = int(arr[1])
HP_arr = input().split(" ")
HP_arr.sort(reverse=True)
HP_arr = [int(i) for i in HP_arr ]
while(True):
if(K > 0):
HP_arr.pop(0)
K -= 1
else:
break
print(sum(HP_arr))
``` | instruction | 0 | 84,817 | 2 | 169,634 |
No | output | 1 | 84,817 | 2 | 169,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
n, k = map(int, input().split())
if n <= k:
print(0)
elif k == 0:
print(sum(h))
else:
h = sorted(list(map(int, input().split())))
print(sum(h[:n-k]))
``` | instruction | 0 | 84,818 | 2 | 169,636 |
No | output | 1 | 84,818 | 2 | 169,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
N, K = map(int, input().split())
H = [int(N) for N in input().split()]
for i in range(0, K):
max_index = H.index(max(H))
H[max_index] = 0
print(sum(int(i) for i in H))
``` | instruction | 0 | 84,819 | 2 | 169,638 |
No | output | 1 | 84,819 | 2 | 169,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
* Attack: Fennec chooses one monster. That monster's health will decrease by 1.
* Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
Constraints
* 1 \leq N \leq 2 \times 10^5
* 0 \leq K \leq 2 \times 10^5
* 1 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 ... H_N
Output
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
Examples
Input
3 1
4 1 5
Output
5
Input
8 9
7 9 3 2 3 8 4 6
Output
0
Input
3 0
1000000000 1000000000 1000000000
Output
3000000000
Submitted Solution:
```
#C
NK = input().split(' ')
N = int(NK[0])
K = int(NK[1])
Hi = input().split(' ')
Hi.sort()
for s in range(K):
Hi.pop(N - 1 - s)
count = 0
for j in range(N-K):
count += int(Hi[j])
print(count)
``` | instruction | 0 | 84,820 | 2 | 169,640 |
No | output | 1 | 84,820 | 2 | 169,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,903 | 2 | 171,806 |
Tags: brute force, math
Correct Solution:
```
r1,r2=map(int,input().split())
c1,c2=map(int,input().split())
d1,d2=map(int,input().split())
c=((c1-d1)+r2)//2
b=((r1-c1)+d2)//2
a=r1-b
d=d1-a
e={a,b,c,d}
if len(e)==4 and 10>a>0 and 10>b>0 and 10>c>0 and 10>d>0:
if a+b==r1 and c+d==r2 and a+c==c1 and b+d==c2 and a+d==d1 and b+c==d2:
print(a,b)
print(c,d)
else: print(-1)
else: print(-1)
"""
a+b=r1 c+d=r2
a+c=c1 b+d=c2
a+d=d1 b+c=d2
b-c=r1-c1 c-b=r2-c2
b+c=d2
2b=(r1-c1)+d2
c-d=c1-d1
c+d=r2
2c=(c1-d1)+r2
"""
``` | output | 1 | 85,903 | 2 | 171,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,904 | 2 | 171,808 |
Tags: brute force, math
Correct Solution:
```
r1,r2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
ans = []
a = (r1+c1-d2)//2
ans.append(a)
b = r1 - a
ans.append(b)
c = c1 - a
ans.append(c)
d = d1 - a
ans.append(d)
ans = list(set(ans))
if(len(ans)<4):
print(-1)
elif(ans[3]>9):
print(-1)
elif(a*b*c*d <=0):
print(-1)
elif(max(a,b,c,d)>9):
print(-1)
elif((c+d)!=r2 or (b+d)!=c2 or (c+b)!=d2):
print(-1)
else:
print(a,b)
print(c,d)
``` | output | 1 | 85,904 | 2 | 171,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,905 | 2 | 171,810 |
Tags: brute force, math
Correct Solution:
```
r1,r2=map(int,input().split())
c1,c2=map(int,input().split())
d1,d2=map(int,input().split())
a=(r1+c1-d2)//2
b=r1-a
c=c1-a
d=c2-b
if a+d==d1 and b+c==d2 and a+b==r1 and c+d==r2 and a+c==c1 and b+d==c2 and len(set([a,b,c,d]))==4 and len(set([a,b,c,d]))==4 and max(a,b,c,d)<10 and min(a,b,c,d)>0:
print(a,b)
print(c,d)
else:
print(-1)
``` | output | 1 | 85,905 | 2 | 171,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,906 | 2 | 171,812 |
Tags: brute force, math
Correct Solution:
```
r1,r2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
res = [[-1]]
for i in range(1,10):
for j in range(1,10):
for k in range(1,10):
for l in range(1,10):
if i + j == r1 and i + k == c1 and i +l == d1 and j +l == c2 and k +l == r2 and j+k == d2 :
if len(set([i,j,k,l])) == 4:
res = [[i,j],[k,l]]
[print(*i) for i in res]
``` | output | 1 | 85,906 | 2 | 171,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,907 | 2 | 171,814 |
Tags: brute force, math
Correct Solution:
```
r1,r2=map(int,input().split())
c1,c2=map(int,input().split())
d1,d2=map(int,input().split())
a=(r1+c1-d2)//2
b=c1-a
c=r1-a
d=d1-a
l={a,b,c,d}
if len(l)<4 or min(l)<1 or max(l)>9 or b+d!=r2 or a+d!=d1 or c+d!=c2:
print(-1)
else:
print(a,c)
print(b,d)
``` | output | 1 | 85,907 | 2 | 171,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,908 | 2 | 171,816 |
Tags: brute force, math
Correct Solution:
```
def solve():
def readinput():
return map(int, input().strip().split())
r1, r2 = readinput()
c1, c2 = readinput()
d1, d2 = readinput()
for g1 in range(1, 10):
for g2 in range(1, 10):
for g3 in range(1, 10):
for g4 in range(1, 10):
s = set([g1, g2, g3, g4])
if len(s) == 4:
if r1 == g1 + g2 and r2 == g3 + g4 and c1 == g1 + g3 and c2 == g2 + g4 and d1 == g1 + g4 and d2 == g2 + g3:
return f"{g1} {g2}\n{g3} {g4}"
return -1
print(solve())
``` | output | 1 | 85,908 | 2 | 171,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,909 | 2 | 171,818 |
Tags: brute force, math
Correct Solution:
```
r1,r2 = input().split(" ")
c1,c2 = input().split(" ")
d1,d2 = input().split(" ")
r1,r2,c1,c2,d1,d2 = int(r1),int(r2),int(c1),int(c2),int(d1),int(d2)
ar1 = []
z = True
m = max(c1,c2)
if(r1+r2 == c1+c2 == d1+d2):
for n in range((r1-1)//2):
ar1.append([r1-1-n,1+n])
for n in ar1:
if n[0] < 10 and n[0] <= m:
ar2 = []
ar2.append(c1-n[0])
ar2.append(r2-ar2[0])
if(n[0] == ar2[0] or n[1] == ar2[1] or ar2[0] == ar2[1] or n[0] == ar2[1] or n[1] == ar2[0]):
n[0],n[1] = n[1],n[0]
ar2 = []
ar2.append(c1-n[0])
ar2.append(r2-ar2[0])
if not (n[0] == ar2[0] or n[1] == ar2[1] or ar2[0] == ar2[1] or n[0] == ar2[1] or n[1] == ar2[0]):
if(n[0]+ar2[1] == d1 and n[1] + ar2[0] == d2 and ar2[0] < 10 and ar2[1] < 10 and ar2[0] > 0 and ar2[1] > 0):
print(n[0],n[1])
print(ar2[0],ar2[1])
z = False
break
else:
if(n[0]+ar2[1] == d1 and n[1] + ar2[0] == d2 and ar2[0] < 10 and ar2[1] < 10 and ar2[0] > 0 and ar2[1] > 0):
print(n[0],n[1])
print(ar2[0],ar2[1])
z = False
break
else:
n[0],n[1] = n[1],n[0]
ar2 = []
ar2.append(c1-n[0])
ar2.append(r2-ar2[0])
if not(n[0] == ar2[0] or n[1] == ar2[1] or ar2[0] == ar2[1] or n[0] == ar2[1] or n[1] == ar2[0]):
if(n[0]+ar2[1] == d1 and n[1] + ar2[0] == d2 and ar2[0] < 10 and ar2[1] < 10 and ar2[1] > 0 and ar2[0] > 0):
print(n[0],n[1])
print(ar2[0],ar2[1])
z = False
break
if z:
print("-1")
else:
print("-1")
``` | output | 1 | 85,909 | 2 | 171,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | instruction | 0 | 85,910 | 2 | 171,820 |
Tags: brute force, math
Correct Solution:
```
r1, r2 = list(map(int, input().split()))
c1, c2 = list(map(int, input().split()))
d1, d2 = list(map(int, input().split()))
for i in range(1, 10):
for j in range(1, 10):
if i == j:
continue
for k in range(1, 10):
if i == k or j == k:
continue
for l in range(1, 10):
if i == l or j == l or k == l:
continue
if i + j == r1 and k + l == r2 and i + k == c1 and j + l == c2 and i + l == d1 and j + k == d2:
print(i, j)
print(k, l)
exit()
print(-1)
``` | output | 1 | 85,910 | 2 | 171,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
__author__ = 'asmn'
r1,r2=tuple(map(int,input().split()))
c1,c2=tuple(map(int,input().split()))
d1,d2=tuple(map(int,input().split()))
for a11 in range(1,10):
a12=r1-a11
a21=c1-a11
a22=c2-a12
if a21+a22==r2 and a11+a22==d1 and a12+a21==d2 and 1<=a12<=9 and 1<=a21<=9 and 1<=a22<=9 and a12 !=a11 and a21!=a11 and a21!=a12 and a22 != a11 and a22!=a12 and a22!=a21:
print('%d %d\n%d %d'%(a11,a12,a21,a22))
break
else:
print(-1)
``` | instruction | 0 | 85,911 | 2 | 171,822 |
Yes | output | 1 | 85,911 | 2 | 171,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
r1,r2=map(int,input().split())
c1,c2=map(int,input().split())
d1,d2=map(int,input().split())
a=(r1+c1-d2)/2
b=r1-a;c=c1-a;d=d1-a
A=set()
A.add(a);A.add(b);A.add(c);A.add(d)
if(a>9 or b>9 or c>9 or d>9):
print("-1")
elif(a<1 or c<1 or b<1 or d<1):
print("-1")
elif(a!=int(a)):
print("-1")
elif(len(A)<4):
print("-1")
elif(a+b!=r1 or c+d !=r2 or a+c !=c1 or b+d!=c2 or a+d!=d1 or b+c !=d2):
print("-1")
else:
print(int(a),int(b))
print(int(c),int(d))
``` | instruction | 0 | 85,912 | 2 | 171,824 |
Yes | output | 1 | 85,912 | 2 | 171,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
import sys
r1, r2 = map(int, input().split())
c1, c2 = map(int, input().split())
d1, d2 = map(int, input().split())
lst = []
r1l = []
r2l = []
c1l = []
c2l = []
d1l = []
d2l = []
newlist = []
perfectlist = []
for i in range(10):
for y in range(10):
lst.append([i,y])
for item in lst:
if sum(item) == r1:
r1l.append(item)
if sum(item) == r2:
r2l.append(item)
if sum(item) == c1:
c1l.append(item)
if sum(item) == c2:
c2l.append(item)
if sum(item) == d1:
d1l.append(item)
if sum(item) == d2:
d2l.append(item)
for item1 in r1l:
for item2 in r2l:
if item1[0] + item2[0] == c1 and item1[1] + item2[1] == c2:
newlist.append([item1,item2])
for item in newlist:
r11,r22 = item
if r11[0] + r22[1] == d1 and r11[1] + r22[0] == d2:
perfectlist.append([r11,r22])
if perfectlist == []:
print(-1)
sys.exit()
y = perfectlist[0]
if y == [] or y[0][0] == y[0][1] or y[0][0] == y[1][0] or y[0][0] == y[1][1] or y[0][1] == y[1][0] or y[0][1] == y[1][1] or y[1][1] == y[1][0] or y[0][0] == 0 or y[0][1] == 0 or y[1][0] == 0 or y[1][1] == 0:
print(-1)
sys.exit()
print(y[0][0],y[0][1])
print(y[1][0],y[1][1])
``` | instruction | 0 | 85,913 | 2 | 171,826 |
Yes | output | 1 | 85,913 | 2 | 171,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
from sys import stdin,stdout
i1 = lambda : int(stdin.readline())
iia = lambda : map(int, stdin.readline().split())
isa = lambda: stdin.readline().split()
r1, r2 = iia()
c1, c2 = iia()
d1, d2 = iia()
if (c2 + r2 - d2) % 2 == 0:
d = (c2 + r2 - d2) // 2
c = r2 - d
b = c2 - d
a = r1 - b
temp = [a, b, c, d]
if len(set(temp)) != 4:
print(-1)
else:
for i in temp:
if not (i > 0 and i < 10):
print(-1)
break
else:
print(a, b)
print(c, d)
else:
print(-1)
``` | instruction | 0 | 85,914 | 2 | 171,828 |
Yes | output | 1 | 85,914 | 2 | 171,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
import math
r = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
x3 = math.ceil((c[0] + d[1] - r[0])/2)
x1 = c[0] - x3
x2 = d[1] - x3
x4 = r[1] - x3
#print(x1,x2)
#print(x3,x4)
if (x3 > 9) or (x1 > 9) or (x2 > 9) or (x4 > 9) or (x3 <= 0) or (x1 <= 0) or (x2 <= 0) or (x4 <= 0):
print(-1)
#print(0)
elif x3 == x1 or x3 == x2 or x3 == x4 or x1 == x2 or x1 == x4 or x2 == x4 :
print(-1)
#print(1)
else:
print(x1,x2)
print(x3,x4)
``` | instruction | 0 | 85,915 | 2 | 171,830 |
No | output | 1 | 85,915 | 2 | 171,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
k=[]
for i in range(3):
k.append(list(map(int,input().split())))
r1,r2,c1,c2,d1,d2=k[0][0],k[0][1],k[1][0],k[1][1],k[2][0],k[2][1]
x1=(r1-d2+c1)//2
x2=r1-x1
x3=(d2-r1+c1)//2
x4=d1-x1
if x1<0 or x2<0 or x3<0 or x4<0 or x1>9 or x2>9 or x3>9 or x4>9:print(-1)
else:
print(x1,x2)
print(x3,x4)
``` | instruction | 0 | 85,916 | 2 | 171,832 |
No | output | 1 | 85,916 | 2 | 171,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
r1,r2=map(int,input().split())
c1,c2=map(int,input().split())
d1,d2=map(int,input().split())
flag=0
for i in range(1,10):
l=[]
x1=i
y1=r1-x1
x2=c1-x1
y2=c2-r1+x1
if(0<y1<10 and 0<x2<10 and 0<y2<10):
l.append(x1)
l.append(y2)
l.append(y1)
l.append(x2)
if(len(set(l))==4):
flag=1
print(x1,y1)
print(x2,y2)
break;
if(flag==0):
print("-1")
``` | instruction | 0 | 85,917 | 2 | 171,834 |
No | output | 1 | 85,917 | 2 | 171,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
Submitted Solution:
```
r1,r2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
a=0 ;b=0;c=0;d=0
if (r1+c1-d2)%2==0:
a = (r1+c1-d2)//2
if (r1+c2-d1)%2==0:
b = (r1-d1+c2)//2
c = c1-a
d = d1-a
if a and b and c and d and a!=b and c!=d:
print(a,b)
print(c,d)
else:
print(-1)
``` | instruction | 0 | 85,918 | 2 | 171,836 |
No | output | 1 | 85,918 | 2 | 171,837 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,720 | 2 | 173,440 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
def main():
t=int(input())
allans=[]
for _ in range(t):
n=int(input()) # monsters
a=readIntArr()
m=int(input()) # heroes
ps=[] # [p,s]
for __ in range(m):
ps.append(readIntArr())
maxMonsterPower=max(a)
maxHeroPower=0
for p,s in ps:
maxHeroPower=max(maxHeroPower,p)
if maxMonsterPower>maxHeroPower:
allans.append(-1)
continue
maxPower=[-1 for _ in range(n+1)] # maxPower[endurance] is the max power of all heroes with s>=endurance
for p,s in ps:
maxPower[s]=max(maxPower[s],p)
# print(maxPower)
for i in range(n-1,-1,-1):
maxPower[i]=max(maxPower[i],maxPower[i+1])
# print('maxPower:{}'.format(maxPower))
currMonst=0
nDays=0
while currMonst<n:
nDays+=1
nextMonst=currMonst
monstMax=a[nextMonst]
for nMonst in range(1,n+1):
# print('maxP:{} nMonst:{} a:{} nextMonst:{}'.format(maxPower,nMonst,a,nextMonst))
if maxPower[nMonst]<monstMax:
assert nMonst!=1 # should be larger than 1
break
nextMonst+=1
if nextMonst==n:
break
monstMax=max(monstMax,a[nextMonst])
# print('currMonst:{} nDays:{} nMonst:{} nextMonst:{}'.format(currMonst,nDays,nMonst,nextMonst))
assert nextMonst>currMonst
currMonst=nextMonst
allans.append(nDays)
multiLineArrayPrint(allans)
return
import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
# input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.
def oneLineArrayPrint(arr):
print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
# def readFloatArr():
# return [float(x) for x in input().split()]
def makeArr(defaultVal,dimensionArr): # eg. makeArr(0,[n,m])
dv=defaultVal;da=dimensionArr
if len(da)==1:return [dv for _ in range(da[0])]
else:return [makeArr(dv,da[1:]) for _ in range(da[0])]
def queryInteractive(x,y):
print('? {} {}'.format(x,y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print('! {}'.format(ans))
sys.stdout.flush()
inf=float('inf')
MOD=10**9+7
for _abc in range(1):
main()
``` | output | 1 | 86,720 | 2 | 173,441 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,721 | 2 | 173,442 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
import math
from collections import Counter
import math
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
d=[0]*(n+1)
for i in range(m):
u,v=map(int,input().split())
d[v]=max(d[v],u)
for i in range(n-1,-1,-1):
d[i]=max(d[i],d[i+1])
#print(d)
ans=1
cnt=1
ma=0
if d[1]<max(arr):
ans=-1
else:
for i in arr:
ma = max(ma, i)
if d[cnt] < ma:
cnt = 1
ans += 1
ma=i
cnt += 1
print(ans)
``` | output | 1 | 86,721 | 2 | 173,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,722 | 2 | 173,444 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
mod=10**9+7
import sys
sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
from bisect import bisect_right as br #c++ upperbound
import itertools
import collections
import math
import heapq
import random
def modinv(n,p):
return pow(n,p-2,p)
def ncr(n,r,p): #for using this uncomment the lines calculating fact and ifact
t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
return t
def cin():
return map(int,sin().split())
def ain(): #takes array as input
return list(map(int,sin().split()))
def sin():
return input()
def inin():
return int(input())
def GCD(x,y):
while(y):
x, y = y, x % y
return x
"""*******************************************************"""
def main():
t=inin()
for _ in range(t):
n=inin()
a=ain()
m=inin()
p=[]
e=[]
d={}
for i in range(m):
j,k=cin()
p.append((j,k))
p.sort(reverse=True)
x=0
for i in p:
if(i[1]>x):
e.append(i)
x=max(x,i[1])
y=n-1
p=[]
for i in e:
p.append(i[0])
d[i[0]]=i[1]
p.sort()
nn=len(p)
ans=0
# print(a,p,d,ans)
b=[]
m=0
j=0
for i in a:
m=max(i,m)
j+=1
x=bisect.bisect_right(p,m-1,0,nn-1)
if(m>p[x]):
ans=-2
break
if(j>d[p[x]]):
ans+=1
j=1
m=i
# print(i)
print(ans+1)
######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO,self).read()
def readline(self):
while self.newlines == 0:
s = self._fill(); self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s:self.buffer.write(s.encode('ascii'))
self.read = lambda:self.buffer.read().decode('ascii')
self.readline = lambda:self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# Cout implemented in Python
import sys
class ostream:
def __lshift__(self,a):
sys.stdout.write(str(a))
return self
cout = ostream()
endl = '\n'
# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
conv = ord if py2 else lambda x:x
A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
try:
while True:
if s[i] >= b'0' [0]:
numb = 10 * numb + conv(s[i]) - 48
elif s[i] == b'-' [0]: sign = -1
elif s[i] != b'\r' [0]:
A.append(sign*numb)
numb = zero; sign = 1
i += 1
except:pass
if s and s[-1] >= b'0' [0]:
A.append(sign*numb)
return A
if __name__== "__main__":
main()
``` | output | 1 | 86,722 | 2 | 173,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,723 | 2 | 173,446 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
import bisect
import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
ar=list(map(int,input().split()))
m=int(input())
po=[]
for i in range(m):
po.append(list(map(int,input().split())))
po.sort(key=lambda x:x[0])
en=[0]*m
powd=[]
ma=0
for i in range(1,m+1):
powd.append(po[i-1][0])
ma=max(ma,po[-i][1])
en[-i]=ma
if(max(ar)>max(powd)):
print(-1)
else:
ans=1
count=0
prev=bisect.bisect_left(powd,ar[0])
for i in range(n):
xx=bisect.bisect_left(powd,ar[i])
if(xx>=prev):
prev=xx
if(en[prev]>=count+1):
count+=1
else:
if(xx<prev):
prev=xx
count=1
ans+=1
print(ans)
``` | output | 1 | 86,723 | 2 | 173,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,724 | 2 | 173,448 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def cons(n,x):
xx = n.bit_length()
dp = [[0]*n for _ in range(xx)]
dp[0] = x
for i in range(1,xx):
for j in range(n-(1<<i)+1):
dp[i][j] = max(dp[i-1][j],dp[i-1][j+(1<<(i-1))])
return dp
def ask(l,r,dp):
""" l and r inclusive 0 based"""
xx1 = (r-l+1).bit_length()-1
return max(dp[xx1][l],dp[xx1][r-(1<<xx1)+1])
def solve(n,a):
day = [0]*(n+1)
for _ in range(int(input())):
p,s = map(int,input().split())
day[s] = max(day[s],p)
for i in range(n-1,-1,-1):
day[i] = max(day[i],day[i+1])
if max(a) > day[0]:
return -1
dp = cons(n,a)
val,i = 0,0
while i != n:
hi,lo,ans = n-1,i,i
while hi >= lo:
mid = (hi+lo)//2
maxi = ask(i,mid,dp)
if day[mid-i+1] >= maxi:
lo = mid+1
ans = mid
else:
hi = mid-1
i = ans+1
val += 1
return val
def main():
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
print(solve(n,a))
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self,file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd,self.buffer.getvalue())
self.buffer.truncate(0),self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self,file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s:self.buffer.write(s.encode("ascii"))
self.read = lambda:self.buffer.read().decode("ascii")
self.readline = lambda:self.buffer.readline().decode("ascii")
sys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)
input = lambda:sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | output | 1 | 86,724 | 2 | 173,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,725 | 2 | 173,450 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------
for _ in range(int(input())):
n = int(input())
a = list(mapi())
m = int(input())
heroes = []
mxp = defaultdict(int)
for i in range(m):
p,s =mapi()
heroes.append([p,s])
mxp[s] = max(mxp[s],p)
for i in range(n-1,-1,-1):
mxp[i] = max(mxp[i+1],mxp[i])
#print(*mxp)
if mxp[0]<max(a):
print(-1)
continue
res = 0
cnt = 0
mx = 0
for x in a:
cnt+=1
mx = max(mx,x)
if mxp[cnt]<mx:
res+=1
mx = x
cnt = 1
if cnt>0:
res+=1
print(res)
``` | output | 1 | 86,725 | 2 | 173,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,726 | 2 | 173,452 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
t = int(input())
ANS = []
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
m = int(input())
ps = [list(map(int, input().split())) for _ in range(m)]
p = [0] * (n + 1)
for i in range(m):
p[ps[i][1]] = max(p[ps[i][1]], ps[i][0])
for i in range(n)[::-1]:
p[i] = max(p[i], p[i + 1])
if p[1] < max(a):
print(-1)
continue
ans = 0
mx = 0
cnt = 0
i = 0
for x in a:
cnt += 1
mx = max(mx, x)
if p[cnt] < mx:
ans += 1
mx = x
cnt = 1
if cnt:
ans += 1
print(ans)
``` | output | 1 | 86,726 | 2 | 173,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,727 | 2 | 173,454 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
class RangeMinimumQuery:
def __init__(self, n, func=min, inf=float("inf")):
self.n0 = 2**(n-1).bit_length()
self.op = func
self.inf = inf
self.data = [self.inf]*(2*self.n0-1)
def query(self, l,r):
l += self.n0
r += self.n0
res = self.inf
while l < r:
if r&1:
r -= 1
res = self.op(res, self.data[r-1])
if l&1:
res = self.op(res, self.data[l-1])
l += 1
l >>=1
r >>=1
return res
def update(self, i, x):
i += self.n0-1
self.data[i] = x
while i+1:
i = ~-i//2
self.data[i] = self.op(self.data[2*i+1], self.data[2*i+2])
def solve():
n = int(input())
a = list(map(int, input().split()))
RMQ = RangeMinimumQuery(n, func=max, inf=0)
for i, ai in enumerate(a):
RMQ.update(i, ai)
m = int(input())
ps = [list(map(int, input().split())) for i in range(m)]
bst = [0]*(n+1)
for p,s in ps:
bst[s] = max(bst[s], p)
for i in reversed(range(1,n+1)):
bst[i-1] = max(bst[i-1], bst[i])
cur = -1
ans = 0
while cur != n-1:
left = cur
right = n
while right-left>1:
mid = (right+left)//2
x = mid-cur
if RMQ.query(cur+1, mid+1) > bst[x]:
right=mid
else:
left=mid
if left == cur:
print(-1)
return
cur = left
ans += 1
print(ans)
t = int(input())
for i in range(t):
solve()
``` | output | 1 | 86,727 | 2 | 173,455 |
Provide tags and a correct Python 2 solution for this coding contest problem.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1 | instruction | 0 | 86,728 | 2 | 173,456 |
Tags: binary search, data structures, dp, greedy, sortings, two pointers
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
pr=stdout.write
raw_input = stdin.readline
def ni():
return int(raw_input())
def li():
return list(map(int,raw_input().split()))
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return (map(int,stdin.read().split()))
range = xrange # not for python 3.0+
# main code
for t in range(ni()):
n=ni()
l=li()
m=ni()
dp=[0]*(n+1)
i=0
for i in range(m):
x,y=li()
dp[y]=max(dp[y],x)
f=0
ans=0
for i in range(n-1,0,-1):
dp[i]=max(dp[i+1],dp[i])
i=0
while i<n:
if l[i]>dp[1]:
f=1
break
ln=1
mx=l[i]
while i<n-1 and dp[ln+1]>=max(mx,l[i+1]):
i+=1
ln+=1
mx=max(mx,l[i])
ans+=1
i+=1
if f:
pn(-1)
else:
pn(ans)
``` | output | 1 | 86,728 | 2 | 173,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
import math
#n,m=map(int,input().split())
from collections import Counter
#for i in range(n):
import math
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
d=[0]*(n+1)
for i in range(m):
u,v=map(int,input().split())
d[v]=max(d[v],u)
for i in range(n-1,-1,-1):
d[i]=max(d[i],d[i+1])
ans=1
cnt=1
ma=0
if d[1]<max(arr):
ans=-1
else:
for i in arr:
ma = max(ma, i)
if d[cnt] < ma:
cnt = 1
ans += 1
ma=i
cnt += 1
print(ans)
``` | instruction | 0 | 86,729 | 2 | 173,458 |
Yes | output | 1 | 86,729 | 2 | 173,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
import sys
input = sys.stdin.readline
t = int(input())
ANS = []
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
m = int(input())
ps = [list(map(int, input().split())) for _ in range(m)]
p = [0] * (n+1)
for i in range(m):
p[ps[i][1]] = max(p[ps[i][1]], ps[i][0])
for i in range(n)[::-1]:
p[i] = max(p[i], p[i + 1])
if p[1] < max(a):
ANS.append(-1)
continue
ans = 0
mx = 0
cnt = 0
i = 0
for x in a:
cnt += 1
mx = max(mx, x)
if p[cnt] < mx:
ans += 1
mx = x
cnt = 1
if cnt:
ans += 1
ANS.append(ans)
print('\n'.join(map(str, ANS)))
``` | instruction | 0 | 86,730 | 2 | 173,460 |
Yes | output | 1 | 86,730 | 2 | 173,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
import sys
input = sys.stdin.readline
def init_max(init_max_val):
#set_val
for i in range(n):
seg_max[i+num_max-1]=init_max_val[i]
#built
for i in range(num_max-2,-1,-1) :
seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2])
def update_max(k,x):
k += num_max-1
seg_max[k] = x
while k:
k = (k-1)//2
seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
def query_max(p,q):
if q<=p:
return ide_ele_max
p += num_max-1
q += num_max-2
res=ide_ele_max
while q-p>1:
if p&1 == 0:
res = max(res,seg_max[p])
if q&1 == 1:
res = max(res,seg_max[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = max(res,seg_max[p])
else:
res = max(max(res,seg_max[p]),seg_max[q])
return res
qq = int(input())
for testcases in [0]*qq:
n = int(input())
a = list(map(int,input().split()))
m = int(input())
p = [-1]*n
for _ in [0]*m:
x,y = map(int,input().split())
p[y-1] = max(p[y-1],x)
tmp_max = -1
for i in range(n-1,-1,-1):
tmp_max = max(tmp_max,p[i])
p[i] = tmp_max
if p[0] < max(a):
print(-1)
continue
if n == 1:
print(1)
continue
if n == 2:
if p[1] >= a[0] and p[1] >= a[1]:
print(1)
else:
print(2)
continue
ide_ele_max = -1
num_max =2**(n-1).bit_length()
seg_max=[ide_ele_max]*2*num_max
init_max(a)
#print(p)
start = 0
res = 0
while start < n:
ok = 0
ng = n-start
while ng-ok > 1:
mid = (ok+ng)//2
if query_max(start,start+mid+1) <= p[mid]:
ok = mid
else:
ng = mid
res += 1
start += ok+1
print(res)
``` | instruction | 0 | 86,731 | 2 | 173,462 |
Yes | output | 1 | 86,731 | 2 | 173,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
from sys import stdin
input=stdin.readline
from bisect import *
t = int(input())
while t:
n = int(input())
a = list(map(int,input().split()))
m = int(input())
p = []
mx = max(a)
flag = 0
for i in range(m):
x, y = map(int,input().split())
if x >= mx:
flag = 1
p.append([y, x])
if not flag:
print(-1)
t -= 1
continue
p.sort(reverse=True)
pre = 0
np = []
for x, y in p:
if pre and y <= pre:
continue
pre = y
np.append([y, x])
ans = 0
i = 0
inf = float('inf')
while i < n:
# print(i)
cnt = 0
mx = 0
flag = 0
for j in range(i, n):
mx = max(mx, a[j])
pos = bisect_left(np, [mx, -inf])
# print(ans,t,mx,np[t])
if np[pos][1] < j - i + 1:
ans += 1
i = j
flag = 1
break
if not flag:
ans += 1
break
print(ans)
t -= 1
``` | instruction | 0 | 86,732 | 2 | 173,464 |
Yes | output | 1 | 86,732 | 2 | 173,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
import bisect
testcases=int(input())
for j in range(testcases):
n=int(input())
monst=list(map(int,input().split()))
m=int(input())
hero=[]
for s in range(m):
p,s=map(int,input().split())
hero.append((p,s))
hero.sort(key= lambda x: x[0])
hero.reverse()
#look for more endurance
power=[]
endu=[]
for s in range(m):
h1=hero[s]
if s==0:
power.append(h1[0])
endu.append(h1[1])
else:
if h1[1]>endu[-1]:
power.append(h1[0])
endu.append(h1[1])
power.reverse()
endu.reverse()
days=0
monsofar=0
for s in range(n):
monster=monst[s]
ind=min(bisect.bisect_left(power,monster+1),len(power)-1)
if endu[ind]>=monsofar+1:
monsofar+=1
else:
days+=1
monsofar=1
if monsofar>=2:
days+=1
if power[-1]<max(monst):
print(-1)
else:
print(days)
``` | instruction | 0 | 86,733 | 2 | 173,466 |
No | output | 1 | 86,733 | 2 | 173,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
import sys
input=sys.stdin.buffer.readline
count=0
for t in range(int(input())):
count+=1
m=int(input())
mon=list(map(int,input().split()))
p=int(input())
store = [[0,0] for i in range(101)]
if(count==34):
print(m,end='')
for i in range(m):
print(mon[i],end='')
for i in range(p):
a,b=map(int,input().split())
store[a]=[a,b]
for i in range(99,-1,-1):
if(store[i][1]<store[i+1][1]):
store[i][0]=store[i+1][0]
store[i][1]=store[i+1][1]
i=0
p_count=99999999999
add=0
flag=1
pre=0
while(i<m):
num=store[mon[i]][0]
count=store[mon[i]][1]
if(num==0):
flag=0
break
if(count>p_count and num>pre):
print(count,p_count,i)
add-=1
count-=p_count
p_count=0
pre=num
while(i<m and count>0):
if(mon[i]>num):
break
count-=1
p_count+=1
i+=1
add+=1
if(flag==0):
print(-1)
else:
print(add)
``` | instruction | 0 | 86,734 | 2 | 173,468 |
No | output | 1 | 86,734 | 2 | 173,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
def f(mp,hero):
hero.sort()
x=0
d=0
try:
while x < len(mp):
e = 0
for i in range(len(hero) - 1, -1, -1):
if hero[i][1] >= mp[x]:
a = i
e = 1
break
if e == 0:
return (-1)
b = hero[a][0]
while b > 0 and hero[a][1] >= mp[x]:
b = b - 1
x = x + 1
d += 1
return (d)
except IndexError:
return(-1)
t=int(input())
for i in range(0,t):
n=int(input())
mp=list(map(int,input().split()))
m=int(input())
hero=[]
for i in range(0,m):
p,s=map(int,input().split())
hero.append((s,p))
print(f(mp,hero))
``` | instruction | 0 | 86,735 | 2 | 173,470 |
No | output | 1 | 86,735 | 2 | 173,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.
The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.
When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:
* if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;
* otherwise, the monster is defeated.
After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated β otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.
Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.
Input
The first line contains one integer t (1 β€ t β€ 10^5) β the number of test cases. Then the test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 2 β
10^5) β the number of monsters in the dungeon.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9), where a_i is the power of the i-th monster.
The third line contains one integer m (1 β€ m β€ 2 β
10^5) β the number of heroes in your party.
Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 β€ p_i β€ 10^9, 1 β€ s_i β€ n) β the power and the endurance of the i-th hero.
It is guaranteed that the sum of n + m over all test cases does not exceed 2 β
10^5.
Output
For each test case print one integer β the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).
Example
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
Output
5
-1
Submitted Solution:
```
for _ in range(int(input())):
input()
m = list(map(int, input().split()))
h = [list(map(int, input().split())) for __ in range(int(input()))]
sas = [0 for i in range(len(m) + 2)]
for i in h:
for j in range(i[1], 0, -1):
if sas[j] < i[0]:
sas[j] = i[0]
else:
break
g = 0
ind = 0
while ind < len(m):
hero = 1
if m[ind] > sas[hero]:
print(-1)
break
test = m[ind]
while test <= sas[hero] and ind + hero < len(m):
hero += 1
test = max(m[ind + hero - 1], test)
if hero > 1:
hero -= 1
ind += hero
g += 1
else:
print(g)
``` | instruction | 0 | 86,736 | 2 | 173,472 |
No | output | 1 | 86,736 | 2 | 173,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,885 | 2 | 173,770 |
Tags: math, number theory
Correct Solution:
```
from math import gcd
for _ in range(int(input())):
k = int(input())
print(100 // gcd(k, 100 - k))
``` | output | 1 | 86,885 | 2 | 173,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,886 | 2 | 173,772 |
Tags: math, number theory
Correct Solution:
```
import math
for _ in range(int(input())):
print('%d' % (100 / math.gcd(int(input()), 100)))
``` | output | 1 | 86,886 | 2 | 173,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,887 | 2 | 173,774 |
Tags: math, number theory
Correct Solution:
```
print(*list([0, 100, 50, 100, 25, 20, 50, 100, 25, 100, 10, 100, 25, 100, 50, 20, 25, 100, 50, 100, 5, 100, 50, 100, 25, 4, 50, 100, 25, 100, 10, 100, 25, 100, 50, 20, 25, 100, 50, 100, 5, 100, 50, 100, 25, 20, 50, 100, 25, 100, 2, 100, 25, 100, 50, 20, 25, 100, 50, 100, 5, 100, 50, 100, 25, 20, 50, 100, 25, 100, 10, 100, 25, 100, 50, 4, 25, 100, 50, 100, 5, 100, 50, 100, 25, 20, 50, 100, 25, 100, 10, 100, 25, 100, 50, 20, 25, 100, 50, 100, 1][int(input())] for i in range(int(input()))), sep='\n')
``` | output | 1 | 86,887 | 2 | 173,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,888 | 2 | 173,776 |
Tags: math, number theory
Correct Solution:
```
import math
for _ in range(int(input())):
k=int(input())
water=100-k
c=math.gcd(water,k)
ans=0
if c==1:
print("100")
else:
water=water//c
k=k//c
print(water+k)
``` | output | 1 | 86,888 | 2 | 173,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,889 | 2 | 173,778 |
Tags: math, number theory
Correct Solution:
```
import math
for i in range(int(input())):
n=int(input())
a=100-n
b=n
if n==100:
print(1)
else:
g=math.gcd(a,b)
print(a//g+b//g)
``` | output | 1 | 86,889 | 2 | 173,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,890 | 2 | 173,780 |
Tags: math, number theory
Correct Solution:
```
import math
for _ in range(int(input())):
n = int(input())
x = math.gcd(n, 100-n)
print(n//x + (100-n)//x)
``` | output | 1 | 86,890 | 2 | 173,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,891 | 2 | 173,782 |
Tags: math, number theory
Correct Solution:
```
import math
for i in range(int(input())):
k = int(input())
print(100//math.gcd(k,100))
``` | output | 1 | 86,891 | 2 | 173,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water. | instruction | 0 | 86,892 | 2 | 173,784 |
Tags: math, number theory
Correct Solution:
```
import math
a=int(input())
for x in range(a):
b=int(input())
if math.gcd(100,b)==1:
print(100)
else:
c=math.gcd(100,b)
print(100//c)
``` | output | 1 | 86,892 | 2 | 173,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water.
Submitted Solution:
```
number=int(input())
def gcd(x,y):
while y!=0:
x,y=y,x%y
return x
for i in range(number):
x=int(input())
print(int(100/(gcd(x,100))))
``` | instruction | 0 | 86,893 | 2 | 173,786 |
Yes | output | 1 | 86,893 | 2 | 173,787 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.