message stringlengths 2 39.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 219 108k | cluster float64 11 11 | __index_level_0__ int64 438 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
for i in range(D):
print(i % 26 + 1)
``` | instruction | 0 | 74,765 | 11 | 149,530 |
Yes | output | 1 | 74,765 | 11 | 149,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
d = int(input())
c = list(map(int, input().split()))
for i in range(d):
s = list(map(int, input().split()))
num = max(s)
print(l.index(num)+1)
``` | instruction | 0 | 74,766 | 11 | 149,532 |
No | output | 1 | 74,766 | 11 | 149,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
import time, random
start = time.time()
D = int(input())
c = list(map(int, input().split()))
s = [None]*D
for i in range(D):
s[i] = list(map(int, input().split()))
current = [0]*26
ans = [None]*D
def greedy():
ans = [None]*D
for i,ss in enumerate(s):
vs = [None]*26
for j in range(26):
vs[j] = (ss[j] + current[j], j)
current[j] += c[j]
vs.sort()
v = vs[-1][1]
ans[i] = v+1
current[v] = 0
return ans
def val(ans):
current = [0]*26
val = 0
for i,(ss, v) in enumerate(zip(s, ans)):
for j in range(26):
current[j] += c[j]
current[v-1] = 0
val += ss[i] - sum(current)
return val
ans = greedy()
num = 2
ren = 0
while (time.time()-start)<=1.90:
v = val(ans)
# print(v)
index = random.sample(range(D),num)
prev = index[0]
tmp = ans[prev]
tmpans = ans[:]
for ind in index[1:]:
ans[prev] = ans[ind]
prev = ind
ans[index[-1]] = tmp
if v<val(ans):
pass
else:
ren += 1
if ren>=100:
num = min(num+1, D)
res = 0
ans = tmpans
# print(v)
write("\n".join(map(str, ans)))
``` | instruction | 0 | 74,767 | 11 | 149,534 |
No | output | 1 | 74,767 | 11 | 149,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]
last = [[0]*27 for _ in range(D+1)]
t = [0]
for i in range(1,D+1):
r = 0
manzoku = 0
for j in range(1,27):
m = s[i][j]
for k in range(1,27):
if k != j:
m -= c[k]*(i-last[i-1][k])
else:
continue
if j == 1:
r = 1
manzoku = m
else:
if manzoku < m:
manzoku = m
r = j
t.append(r)
for j in range(1,27):
if j == r:
last[i][j] = i
else:
last[i][j] = last[i-1][j]
M = D*26
dq = []
for i in range(1,D+1):
for j in range(1,27):
dq.append([i,j])
from copy import deepcopy
for i in range(M):
d,q = dq[i]
t0 = t[d]
last2 = deepcopy(last)
manzoku = s[d][q] - s[d][t0]
for j in range(d,D+1):
if j == d:
last2[d][t0] = last2[d-1][t0]
manzoku -= c[t0] * (d - last2[d][t0])
last2[d][q] = d
manzoku += c[q] * (d - last2[d-1][q])
else:
if last2[j][t0] == d:
last2[j][t0] = last2[d-1][t0]
manzoku -= c[t0] * (d - last2[d][t0])
if last2[j][q] == last2[d-1][q]:
last2[j][q] = d
manzoku += c[q] * (d - last2[d-1][q])
if manzoku > 0:
t[d] = q
last = last2
del t[0]
print(*t,sep='\n')
``` | instruction | 0 | 74,768 | 11 | 149,536 |
No | output | 1 | 74,768 | 11 | 149,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.
* The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.
* Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.
* If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).
Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
Constraints
* D = 365
* Each c_i is an integer satisfying 0\leq c_i \leq 100.
* Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.
Input
Input is given from Standard Input in the following format:
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
Output
Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d. Print D integers t_d to Standard Output in the following format:
t_1
t_2
\vdots
t_D
Any output that does not follow the above format may result in ~~0 points~~ WA for that test case.
Input Generation
Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
Output
1
17
13
14
13
Submitted Solution:
```
ans = [1]*365
for i in range(365):
ans[i]=i%25 + 2
for i in range(365):
print(i,ans[i])
``` | instruction | 0 | 74,769 | 11 | 149,538 |
No | output | 1 | 74,769 | 11 | 149,539 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,802 | 11 | 149,604 |
"Correct Solution:
```
from itertools import accumulate
N, X = map(int, input().split())
BLUs = [tuple(map(int, input().split())) for _ in range(N)]
vs = [(L*B + U*(X-B), i) for i, (B, L, U) in enumerate(BLUs)]
vs.sort(reverse=True)
accV = 0
accVs = [0]
for v, i in vs:
accV += v
accVs.append(accV)
D0 = -sum([L*B for B, L, U in BLUs])
def isOK(k):
q = k // X
r = k % X
for odr, (v, i) in enumerate(vs):
B, L, U = BLUs[i]
d = D0
if odr < q:
d += accVs[q+1] - v
else:
d += accVs[q]
if r <= B:
d += L*r
else:
d += L*B + U*(r-B)
if d >= 0:
return True
return False
ng, ok = -1, N*X
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
``` | output | 1 | 74,802 | 11 | 149,605 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,803 | 11 | 149,606 |
"Correct Solution:
```
import sys
n, x = list(map(int, input().split()))
exams = []
norma = 0
for i, line in enumerate(sys.stdin):
b, l, u = map(int, line.split())
exams.append((u * x - b * (u - l), b, l, u, i))
norma += b * l
exams_sorted = sorted(exams, reverse=True)
remain_norma = norma
sub_d = -1
i = 0
used = set()
for i, (d, b, l, u, ei) in enumerate(exams_sorted):
if remain_norma < d:
sub_d = d
break
remain_norma -= d
used.add(ei)
if sub_d == -1:
print(n * x)
exit()
base_ans = i * x
base_remain_norma = remain_norma
ans = 10 ** 10
for d, b, l, u, i in exams:
if i in used:
curr_remain_norma = base_remain_norma + d - sub_d
else:
curr_remain_norma = base_remain_norma
if curr_remain_norma <= b * l:
extra = (curr_remain_norma - 1) // l + 1
else:
extra = (curr_remain_norma + b * (u - l) - 1) // u + 1
if extra > x:
continue
ans = min(ans, base_ans + extra)
print(ans)
``` | output | 1 | 74,803 | 11 | 149,607 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,804 | 11 | 149,608 |
"Correct Solution:
```
n, x = list(map(int, input().split()))
B = 0
blu = []
s = [0 for i in range(n)]
for i in range(n):
b, l, u = list(map(int, input().split()))
blu.append((b, l, u, x*u-b*u+b*l))
B += b*l
blu.sort(key=lambda x: x[3], reverse=True)
for i in range(n):
if i==0:
s[i] = blu[i][3]
else:
s[i] = s[i-1] + blu[i][3]
ok = n*x
ng = -1
while ok-ng>1:
A = 0
mid = (ok+ng)//2
k = mid//x
t = mid%x
for i in range(n):
if t<=blu[i][0]:
rm = t*blu[i][1]
else:
rm = t*blu[i][2] - blu[i][0]*(blu[i][2]-blu[i][1])
if k==0:
A = max(A, rm)
elif i<k:
A = max(A, s[k]-blu[i][3]+rm)
else:
A = max(A, s[k-1]+rm)
if A>=B:
ok = mid
else:
ng = mid
print(ok)
``` | output | 1 | 74,804 | 11 | 149,609 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,805 | 11 | 149,610 |
"Correct Solution:
```
import math
INF = 10**18
n, x = [int(item) for item in input().split()]
blu = [[int(item) for item in input().split()] for _ in range(n)]
s_score_list = []
full_score_list = []
for i, (b, l, u) in enumerate(blu):
s_score_list.append(b * l)
full_score_list.append([(x-b) * u + b * l, i])
s_score = sum(s_score_list)
full_score_list.sort(reverse=True)
t_score = 0
full_score_set = set()
for i in range(n):
full_score_set.add(full_score_list[i][1])
t_score += full_score_list[i][0]
if t_score >= s_score:
last_index = full_score_list[i][1]
surplus = t_score - s_score
shortage = s_score - t_score + full_score_list[i][0]
break
# Minimize time in full-score-set
max_reduction = 0
for i, (b, l, u) in enumerate(blu):
if i in full_score_set:
if (x-b) * u >= surplus:
max_reduction = max(max_reduction, int(math.floor(surplus / u)))
elif (x-b) * u + b * l >= surplus:
max_reduction = max(max_reduction, (x-b) + int(math.floor((surplus - (x-b)*u) / l)))
ans = x * len(full_score_set) - max_reduction
# Take lest of score in not full_scores
full_score_set.remove(last_index)
min_promotion = INF
for i, (b, l, u) in enumerate(blu):
if i in full_score_set:
continue
if b*l >= shortage:
min_promotion = min(min_promotion, int(math.ceil(shortage / l)))
elif b*l + (x-b)*u >= shortage:
min_promotion = min(min_promotion, b + int(math.ceil((shortage - b*l) / u)))
ans = min(ans, min_promotion + x * len(full_score_set))
print(ans)
``` | output | 1 | 74,805 | 11 | 149,611 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,806 | 11 | 149,612 |
"Correct Solution:
```
N, X = map(int, input().split())
items = []
for i in range(N):
b, l, u = map(int, input().split())
items.append((b, l, u, u * (X - b), - b * l))
items = sorted(items, key=lambda x: -(x[3] - x[4]))
def f(num):
cnt = num // X
mod = num % X
point = 0
for i in range(cnt):
point += items[i][3]
for i in range(cnt, N):
point += items[i][4]
if mod == 0:
if point >= 0:
return True
else:
return False
else:
tmp = -float("inf")
for i, tmp2 in enumerate(items):
b, l, u, d1, d2 = tmp2
if mod >= b:
mul = u * (mod - b)
else:
mul = l * (mod - b)
if i < cnt:
tmp = max(tmp, point - d1 + mul + items[cnt][3] - items[cnt][4])
else:
tmp = max(tmp, point - d2 + mul)
if tmp >= 0:
return True
else:
return False
ok = N * X + 1
ng = - 1
while (ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ok)
``` | output | 1 | 74,806 | 11 | 149,613 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,807 | 11 | 149,614 |
"Correct Solution:
```
from itertools import accumulate
import sys
input = sys.stdin.readline
def solve():
N, X = map(int, input().split())
tests = []
D0 = 0
for _ in range(N):
B, L, U = map(int, input().split())
v = L*B + U*(X-B)
tests.append((v, B, L, U))
D0 -= L*B
tests.sort(reverse=True)
accVs = list(accumulate([0] + tests, lambda accX, X: accX + X[0]))
def isOK(k):
q = k // X
r = k % X
accV = accVs[q+1]
for v, B, L, U in tests[:q]:
d = D0 + accV - v
if r <= B:
d += L*r
else:
d += L*B + U*(r-B)
if d >= 0:
return True
accV = accVs[q]
for v, B, L, U in tests[q:]:
d = D0 + accV
if r <= B:
d += L*r
else:
d += L*B + U*(r-B)
if d >= 0:
return True
return False
ng, ok = -1, N*X
while abs(ok-ng) > 1:
mid = (ng+ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
return ok
print(solve())
``` | output | 1 | 74,807 | 11 | 149,615 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,808 | 11 | 149,616 |
"Correct Solution:
```
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
from bisect import bisect_right, bisect_left
def main():
N, X = LI()
b_l_u = []
for i in range(N):
b_l_u.append(LI())
sum_of_test = [ (b_l_u_i[1]*b_l_u_i[0]+b_l_u_i[2]*(X-b_l_u_i[0]), i) for i,b_l_u_i in enumerate(b_l_u)]
sum_of_test.sort(reverse=True) # O(nlogn)
cumsum_of_test = []
tmp = 0
for i in sum_of_test: # O(n)
tmp += i[0]
cumsum_of_test.append(tmp)
B = sum([l*b for b, l, u in b_l_u]) # O(n)
head = bisect_right(cumsum_of_test, B)-1
cumsum = cumsum_of_test[head]
take_li = []
for j, (sum_, i) in enumerate(sum_of_test): # O(N)
# cumsum の中に入っていたら、引く。
if j <= head:
new_head = bisect_right(cumsum_of_test, B+sum_)-1 # O(log N)
new_cumsum = cumsum_of_test[new_head] - sum_
left = B - new_cumsum
take_1 = X * new_head
else:
left = B - cumsum
take_1 = X*(head+1)
if head==-1: # i番目を下からとっていくコードのみでOK.
left = B
take_1 = 0
b, l, u = b_l_u[i]
from math import ceil
if left/l <= b:
take = ceil(left/l)
else:
take = b + ceil((left - b*l)/u)
if take > X: continue
take_li.append(take+take_1)
print(min(take_li))
main()
``` | output | 1 | 74,808 | 11 | 149,617 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540 | instruction | 0 | 74,809 | 11 | 149,618 |
"Correct Solution:
```
N,X=map(int,input().split())
blu=[list(map(int,input().split())) for i in range(N)]
S=0
data=[]
low=0
high=0
for i in range(N):
b,l,u=blu[i]
high+=b
data.append([u*(X-b)+l*b,i])
S-=b*l
data.sort(reverse=True)
lst=[data[0][0]]
lsls=[data[0][1]]
for i in range(1,N):
lst.append(lst[-1]+data[i][0])
lsls.append(data[i][1])
while high-low>1:
mid=(high+low)//2
ppp=mid//X
qqq=mid%X
SS=S
if ppp>0:
SS+=lst[ppp-1]
num=0
for i in range(ppp,N):
b,l,u=blu[lsls[i]]
if qqq>=b:
num1=b*l+(qqq-b)*u
else:
num1=qqq*l
num=max(num,num1)
SS+=num
SSS=S+lst[ppp]
num=-float("inf")
for i in range(ppp):
zzz,ind=data[i]
b,l,u=blu[ind]
if qqq>=b:
num1=-zzz+b*l+(qqq-b)*u
else:
num1=-zzz+qqq*l
num=max(num,num1)
SSS+=num
SS=max(SS,SSS)
if SS>=0:
high=mid
else:
low=mid
print(high)
``` | output | 1 | 74,809 | 11 | 149,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
import sys,heapq,time
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
n,x = inm()
blu = []
pt = 0
for i in range(n):
b,l,u = inm()
s = u*(x-b) + l*b
v = s/x
t = x
heapq.heappush(blu, (-v,s,t,b,l,u,i))
pt -= l*b
if pt==0:
print(0)
exit()
ans = []
reached = False
sum = 0
while len(blu)>0:
mv,s,t,b,l,u,r = heapq.heappop(blu)
nxtpt = pt + s
ddprint("v {} s {} t {} b {} l {} u {} pt {} nx {} sum {}".format(-mv,s,t,b,l,u,pt,nxtpt,sum))
if nxtpt < 0:
ans.append((s,b,l,u))
pt = nxtpt
sum += t
continue
elif nxtpt == 0: # < (u if pt+l*b<0 else l):
if not reached:
ans.append((s,b,l,u))
pt2 = pt + u*x - u*b + l*b
sum += t
break
else: # nxtpt > 0
m = pt + l*b
ddprint("m {}".format(m))
if m>=0:
t = (-pt+l-1)//l
else:
m = -m
t = b + (m+u-1)//u
if not reached:
ans.append((s,b,l,u))
pt2 = pt + u*x - u*b + l*b
reached = True
s = -pt
ddprint("s/t {} s {} t {}".format(s/t,s,t))
heapq.heappush(blu, (-s/t,s,t,b,l,u,-1))
sum2 = x * (len(ans)-1)
for z in ans[:-1]:
s,b,l,u = z
pt = pt2 - s
m = pt + l*b
if m>=0:
t = (-pt+l-1)//l
else:
t = b+(-m+u-1)//u
if sum2+t < sum:
sum = sum2+t
print(sum)
``` | instruction | 0 | 74,810 | 11 | 149,620 |
Yes | output | 1 | 74,810 | 11 | 149,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
import sys
input = sys.stdin.readline
from itertools import accumulate
def main():
N,X=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
A.sort(key=lambda x:x[2]*(X-x[0])+x[0]*x[1],reverse=True)
ALL=[a[2]*(X-a[0])+a[0]*a[1] for a in A]
SUM=[0]+list(accumulate(ALL))
MAX=0
MINUS=0
for a,r,l in A:
MAX+=a
MINUS+=a*r
OUT=-1
def binsearch(score):
alluse=score//X
rest=score-alluse*X
for ri in range(N):
plus=0
b,l,u=A[ri]
if rest<b:
plus+=rest*l
else:
plus+=rest*u+b*l-b*u
if alluse<=ri:
plus+=SUM[alluse]
else:
plus+=SUM[alluse+1]-ALL[ri]
#print(score,ri,plus)
if plus>=MINUS:
return 1
return 0
while MAX-OUT>1:
mid=(MAX+OUT)//2
if binsearch(mid)==1:
MAX=mid
else:
OUT=mid
print(MAX)
main()
``` | instruction | 0 | 74,811 | 11 | 149,622 |
Yes | output | 1 | 74,811 | 11 | 149,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
from operator import itemgetter
N, X = map(int, input().split())
S = [list(map(int, input().split())) for i in range(N)]
A = []
aoki = 0
for i, (b, l, u) in enumerate(S):
A.append([(X-b)*u + (b)*l, i])
aoki += b*l
A.sort(reverse=True, key=itemgetter(0))
ans = 0
tak = 0
for iaaaa, (a, i) in enumerate(A):
if aoki >= a:
aoki -= a
ans += X
if aoki==0:
print(ans)
exit()
else:
break
mi = float("inf")
aoki_ = aoki
for j in range(iaaaa, N):
a, i = A[j]
b, l, u = S[i]
aoki = aoki_
an, m = divmod(aoki, l)
if m!=0:
an += 1
mi = min(mi, an)
aoki += (u-l) * b
an, m = divmod(aoki, u)
if m!=0:
an += 1
mi = min(mi, an)
ans_ = ans + mi
a, i = A[iaaaa]
aoki_ -= a
#aoki_ = -aoki
anss = (iaaaa)*X
mi = float("inf")
for a, i in A[:iaaaa]:
b, l, u = S[i]
aoki = aoki_ + a
an, m = divmod(aoki, l)
if m!=0:
an += 1
mi = min(mi, an)
aoki += (u-l) * b
an, m = divmod(aoki, u)
if m!=0:
an += 1
mi = min(mi, an)
print(min(ans_, anss+mi))
``` | instruction | 0 | 74,812 | 11 | 149,624 |
Yes | output | 1 | 74,812 | 11 | 149,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
# 解説
def accumulate(a):
su = 0
yield su
for x in a:
su += x
yield su
def solve_agc034c():
from collections import namedtuple
import sys
input = sys.stdin.readline
Test = namedtuple('Test', 'Aoki_score lower_bound upper_bound')
Test.D_partial = lambda self, score: \
self.lower_bound * score if score <= self.Aoki_score \
else self.upper_bound * score - (self.upper_bound - self.lower_bound) * self.Aoki_score
def is_ok(init_rest):
"""init_rest: 勉強に使える時間"""
take, rest = divmod(init_rest, X)
if take > N - 1:
r = take - (N - 1)
take = N - 1
rest += r * X
for i, partial_solve_test in enumerate(tests, start=1):
when_full = partial_solve_test.D_partial(X)
if i <= take:
su = acc[take + 1] - when_full
else:
su = acc[take]
when_partial = partial_solve_test.D_partial(min(X, rest))
d = INIT_D + su + when_partial
if d >= 0:
return True
return False
def binary_search(*, ok, ng, is_ok):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
N, X = map(int, input().split())
tests = []
for _ in range(N):
row = map(int, input().split())
tests.append(Test(*row))
tests.sort(key=lambda test: test.D_partial(X), reverse=True)
# 勝つ科目と負ける科目を決める
# 勝つ科目は重要度をupper_boundにする
# 負ける科目は重要度をlower_boundにする
INIT_D = -sum(test.lower_bound * test.Aoki_score for test in tests)
*acc, = accumulate(test.D_partial(X) for test in tests)
res = binary_search(ok=10 ** 10, ng=-1, is_ok=is_ok)
# D>=0となる勉強時間
print(res)
return
if __name__ == '__main__':
solve_agc034c()
``` | instruction | 0 | 74,813 | 11 | 149,626 |
Yes | output | 1 | 74,813 | 11 | 149,627 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
n,x = inm()
blu = []
pt = 0
for i in range(n):
b,l,u = inm()
v = u - (u-l)*b/x
blu.append((v,b,l,u))
pt -= l*b
blu.sort()
sum = 0
while len(blu)>0:
v,b,l,u = blu.pop()
nxtpt = pt + l*b + u*(x-b)
ddprint("v {} b {} l {} u {} pt {} nx {} sum {}".format(v,b,l,u,pt,nxtpt,sum))
if nxtpt < 0:
pt = nxtpt
sum += x
continue
elif nxtpt == 0:
pt = 0
sum += x
print(sum)
exit()
else: # nxtpt > 0
blu.append((v,b,l,u))
break
# on the next step, we can go above zero
mn = 999999999
for z in blu:
v,b,l,u = z
m = pt + l*b
ddprint("m {}".format(m))
if m>=0:
t = b - (m)//l
else:
m = -m
t = b + (m+u-1)//u
if t>x:
continue
if t<mn:
mn = t
print(sum+mn)
``` | instruction | 0 | 74,814 | 11 | 149,628 |
No | output | 1 | 74,814 | 11 | 149,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
N,X=map(int,input().split())
blu=[list(map(int,input().split())) for i in range(N)]
S=0
data=[]
for i in range(N):
b,l,u=blu[i]
data.append([u*(X-b)+l*b,i])
S-=b*l
data.sort(reverse=True)
flag=[0]*N
ans=0
for i in range(N):
SS=S+data[i][0]
if SS<0:
S=SS
flag[data[i][1]]=1
ans+=X
else:
break
num=float("inf")
for i in range(N):
if flag[i]==1:
continue
b,l,u=blu[i]
if (S+b*l)%u==0:
a=b-(S+b*l)//u
else:
a=b-(S+b*l)//u+1
if S%l==0:
a=min(a,-S//l)
else:
a=min(a,-S//l+1)
num=min(num,a)
ans+=num
print(ans)
``` | instruction | 0 | 74,815 | 11 | 149,630 |
No | output | 1 | 74,815 | 11 | 149,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
def get(list,n):
sum=0
a=[]
for i in range(len(list)):
sum+=list[i][0]*list[i][1]
a.append([(n-list[i][0])*list[i][2],i])
a.sort()
i,z=0,True
count=0
a.reverse()
while i<len(a) and z:
sum-=(100*list[a[i][1]][2])
count+=100
if sum<0:
z=False
else:
i+=1
sum+=100*list[a[i][1]][2]
count-=100
if sum%(list[a[i][1]][2])==0:
count+=sum//list[a[i][1]][2]
else:
count+=sum//(list[a[i][1]][2]+1)
return count
m=list(map(int,input().strip().split()))
l=[]
for i in range(m[0]):
l.append(list(map(int,input().strip().split())))
print(get(l,m[1]))
``` | instruction | 0 | 74,816 | 11 | 149,632 |
No | output | 1 | 74,816 | 11 | 149,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural power.
Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1. (He can only study for an integer number of hours.) However, he cannot score more than X on an exam, since the perfect score for all the exams is X.
Print the minimum number of study hours required for Takahashi to win.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^5
* 0 \leq b_i \leq X (1 \leq i \leq N)
* 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
Output
Print the minimum number of study hours required for Takahashi to win.
Examples
Input
2 100
85 2 3
60 1 1
Output
115
Input
2 100
85 2 3
60 10 10
Output
77
Input
1 100000
31415 2718 2818
Output
31415
Input
10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980
Output
2540
Submitted Solution:
```
n,x = map(int,input().split())
base_score =0
my_score = 0
ans = 0
b = []
l = []
u = []
sco = []
for i in range(n):
ba,la,ua = map(int,input().split())
b.append(ba)
l.append(la)
u.append(ua)
sco.append([ba,la,ua])
base_score += ba*la
#print(base_score)
for i in range(n):
sco[i].append((x*sco[i][2])-(sco[i][0]*(sco[i][2]-sco[i][1])))
sco = sorted(sco, key = lambda a: a[3] )
#print(sco)
while my_score<=base_score:
if (base_score - my_score) <= sco[-1][3]:
k = base_score - my_score
#print(k)
my_score = base_score+1
ans += ((k-1)//sco[-1][1])+1
else:
my_score += sco[-1][3]
ans += x
sco.pop(-1)
#print(sco)
#print(base_score,my_score,ans)
print(ans)
``` | instruction | 0 | 74,817 | 11 | 149,634 |
No | output | 1 | 74,817 | 11 | 149,635 |
Provide a correct Python 3 solution for this coding contest problem.
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.
You are asked to help her by calculating how many weights are required.
<image>
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
<image>
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.
* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Example
Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1 | instruction | 0 | 74,889 | 11 | 149,778 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
s = S()
d = 0
ans = 0
k = 0
for i in s:
if i == "R":
if d == 0:
k = 1
d += 1
d %= 4
if d == 0 and k:ans += 1
else:
if d == 0:
k = 0
d -= 1
d %= 4
print(ans)
return
#B
def B():
while 1:
a,b,d = LI()
if a == b == d == 0:
quit()
ans = []
l = []
m = float("inf")
for x in range(-50000,50001):
if (d-a*x)%b == 0:
y = (d-a*x)//b
k = abs(x)+abs(y)
if k < m:
m = k
for x in range(-50000,50001):
if (d-a*x)%b == 0:
y = (d-a*x)//b
k = abs(x)+abs(y)
if k == m:
ans.append((abs(x),abs(y)))
l.append(a*abs(x)+b*abs(y))
print(*ans[l.index(min(l))])
return
#C
def C():
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#I
def I_():
return
#J
def J():
return
#Solve
if __name__ == "__main__":
B()
``` | output | 1 | 74,889 | 11 | 149,779 |
Provide a correct Python 3 solution for this coding contest problem.
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.
You are asked to help her by calculating how many weights are required.
<image>
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
<image>
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.
* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Example
Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1 | instruction | 0 | 74,890 | 11 | 149,780 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
a,b,c = LI()
if a == 0:
break
r = inf
x = inf
y = inf
for i in range(c*5):
t = a * i
if t < c and (c - t) % b == 0:
tr = c
tx = i
ty = (c-t) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if t >= c and (t-c) % b == 0:
tr = t - c + t
tx = i
ty = (t-c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if (t+c) % b == 0:
tr = t + c + t
tx = i
ty = (t+c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
rr.append('{} {}'.format(x,y))
return '\n'.join(map(str,rr))
print(main())
``` | output | 1 | 74,890 | 11 | 149,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.
You are asked to help her by calculating how many weights are required.
<image>
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
<image>
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.
* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Example
Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
a,b,c = LI()
if a == 0:
break
r = inf
x = inf
y = inf
for i in range(c+1):
t = a * i
if t < c and (c - t) % b == 0:
tr = c
tx = i
ty = (c-t) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if t >= c and (t-c) % b == 0:
tr = t - c + t
tx = i
ty = (t-c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
if (t+c) % b == 0:
tr = t + c + t
tx = i
ty = (t+c) // b
if x+y > tx+ty or (x+y==tx+ty and r > tr):
r = tr
x = tx
y = ty
rr.append('{} {}'.format(x,y))
return '\n'.join(map(str,rr))
print(main())
``` | instruction | 0 | 74,891 | 11 | 149,782 |
No | output | 1 | 74,891 | 11 | 149,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.
Help the Little Elephant to count the answers to all queries.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).
Output
In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.
Examples
Input
7 2
3 1 2 2 3 3 7
1 7
3 4
Output
3
1
Submitted Solution:
```
import sys
from collections import Counter
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
cnt=Counter(a)
maybe={}
for val,c in cnt.items(): # count which may be in each [l:r] and label
if c>=val:
l=len(maybe)
maybe[val]=l
# len(maybe)~sqrt(n)
pref=[[0]*len(maybe)]
for i in range(n):
pref.append(pref[-1][:])
if a[i] in maybe:
pref[-1][maybe[a[i]]]+=1
for _ in range(m):
l,r=map(int,input().split())
cur=0
for val,c in maybe.items():
if pref[r][c]-pref[l-1][c]==val:
cur+=1
print(cur)
``` | instruction | 0 | 75,327 | 11 | 150,654 |
Yes | output | 1 | 75,327 | 11 | 150,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.
Help the Little Elephant to count the answers to all queries.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).
Output
In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.
Examples
Input
7 2
3 1 2 2 3 3 7
1 7
3 4
Output
3
1
Submitted Solution:
```
from collections import defaultdict
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")
n,m=map(int,input().split())
query=[[] for j in range(int(n**0.5)+1)]
arr=list(map(int,input().split()))
for j in range(m):
x,y=map(int,input().split())
query[int(x/n**0.5)].append([x-1,y-1,j])
q=[]
for j in query:
j.sort(key=lambda x:x[1])
for p in j:
q.append(p)
d=defaultdict(lambda:0)
j=0
currL,currR,x= 1,0,0
res=[0]*(m)
while(j<len(q)):
L,R=q[j][0],q[j][1]
while currL < L:
d[arr[currL]]-=1
if d[arr[currL]]==(arr[currL]-1):
x-=1
if d[arr[currL]] == (arr[currL]):
x += 1
currL += 1
while currL > L:
currL -= 1
d[arr[currL]] += 1
if d[arr[currL]]==(arr[currL]+1):
x-=1
if d[arr[currL]]==(arr[currL]):
x+=1
while currR<R:
currR += 1
d[arr[currR]] += 1
if d[arr[currR]]==(arr[currR]+1):
x-=1
if d[arr[currR]] == (arr[currR]):
x += 1
while currR > R:
d[arr[currR]] -= 1
if d[arr[currR]]==(arr[currR]-1):
x-=1
if d[arr[currR]] == (arr[currR]):
x += 1
currR -= 1
res[q[j][2]]=x
j+=1
for j in res:
print(j)
``` | instruction | 0 | 75,328 | 11 | 150,656 |
Yes | output | 1 | 75,328 | 11 | 150,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.
Help the Little Elephant to count the answers to all queries.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).
Output
In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.
Examples
Input
7 2
3 1 2 2 3 3 7
1 7
3 4
Output
3
1
Submitted Solution:
```
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/8/20
for each query l, r; how many x that count of x in range [l, r] equals x
for each query ends with x, query (l, x) with Fenwick tree
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(N, M, A, Q):
bit = [0 for _ in range(N)]
def add(index, val):
while index < N:
bit[index] += val
index |= index + 1
def query(index):
index = min(index, N-1)
s = 0
while index >= 0:
s += bit[index]
index = (index & (index + 1)) - 1
return s
q = collections.defaultdict(list)
for i, (l, r) in enumerate(Q):
q[r].append((l, i))
ans = [0 for _ in range(M)]
vi = collections.defaultdict(list)
for i, v in enumerate(A):
vi[v].append(i)
lv = len(vi[v])
if lv >= v:
add(i, 1)
if lv == v + 1:
add(vi[v][-v-1], -1)
if lv > v + 1:
add(vi[v][-v-2], 1)
for l, qi in q[i]:
ans[qi] = query(i) - query(l-1)
print('\n'.join(map(str, ans)))
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
Q = []
for i in range(M):
l, r = map(int, input().split())
Q.append((l-1, r-1))
solve(N, M, A, Q)
``` | instruction | 0 | 75,334 | 11 | 150,668 |
No | output | 1 | 75,334 | 11 | 150,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,385 | 11 | 150,770 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
number_of_problems, number_of_prepared_problems = map(int, input().split())
required_problems = list(map(int, input().split()))
prepared_problems = list(map(int, input().split()))
idx_required = idx_prepared = 0
while idx_required < number_of_problems and idx_prepared < number_of_prepared_problems:
if prepared_problems[idx_prepared] >= required_problems[idx_required]:
idx_required += 1
idx_prepared += 1
result = number_of_problems - idx_required
print(result)
``` | output | 1 | 75,385 | 11 | 150,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,386 | 11 | 150,772 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
def inp():
return map(int, input().split())
n, m = inp()
a = list(inp())
b = list(inp())
count = 0
j = 0
for i in range(n):
while j < m:
if b[j] >= a[i]:
count += 1
j += 1
break
else:
j += 1
print(n - count)
``` | output | 1 | 75,386 | 11 | 150,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,387 | 11 | 150,774 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
li = [0] * n
k = 0
for i in range(m):
#b[i]
for j in range(k, n):
if li[j] == 0 and a[j] <= b[i]:
li[j] = 1
k = j
break
count = 0
for i in li:
if i == 0:
count += 1
print(count)
``` | output | 1 | 75,387 | 11 | 150,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,388 | 11 | 150,776 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = map(int,input().split())
must = list(map(int,input().split()))
have = list(map(int,input().split()))
mi = hi = 0
while mi<n and hi<m:
if must[mi]>have[hi]:
#move on to next have elem
hi+=1
else:
# move on to next needed must
mi+=1
hi+=1
print(n-mi)
``` | output | 1 | 75,388 | 11 | 150,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,389 | 11 | 150,778 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
from bisect import bisect_left
def binr(a, x, lo=0, hi=None):
hi = hi if hi is not None else len(a)
pos = bisect_left(a,x,lo,hi)
if pos < hi:
return pos
else:
return -1
n,m = map(int,input().split())
d = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
fl = True
ans = 0
for i in d:
if (i not in a):
fl = False
if fl == True:
print(0)
exit()
for i in range(n):
if d[i] in a:
d[i] = 0
r = binr(a,d[i])
if r == -1:
ans += 1
else:
a[r] = -1
a.sort()
print(ans)
``` | output | 1 | 75,389 | 11 | 150,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,390 | 11 | 150,780 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
while i < n and j < m:
if a[i] <= b[j]:
i += 1
j += 1
print(n - i)
``` | output | 1 | 75,390 | 11 | 150,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,391 | 11 | 150,782 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
n,m = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
i=0
j=0
while i<n and j<m:
if a[i] <= b[j]:
i+=1
j+=1
print(n-i)
``` | output | 1 | 75,391 | 11 | 150,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | instruction | 0 | 75,392 | 11 | 150,784 |
Tags: brute force, greedy, two pointers
Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
j = 0
for i in range(n):
while j < m:
if a[i] <= b[j]:
cnt += 1
j += 1
break
else:
j += 1
print(n - cnt)
``` | output | 1 | 75,392 | 11 | 150,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n, m = map(int, input().split())
a = [int(k) for k in input().split()]
b = [int(j) for j in input().split()]
f = 0
f1 = 0
while f < n and f1 < m:
if b[f1] >= a[f]:
f += 1
f1 += 1
print(n - f)
``` | instruction | 0 | 75,393 | 11 | 150,786 |
Yes | output | 1 | 75,393 | 11 | 150,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n, m = map(int, input().split())
good = list(map(int, input().split()))
prepared = list(map(int, input().split()))
i = 0
j = 0
count = 0 # Number of good prepared problems
while i < n and j < m:
if prepared[j] >= good[i]:
i += 1
j += 1
count += 1
else:
j += 1
print(n - count)
``` | instruction | 0 | 75,394 | 11 | 150,788 |
Yes | output | 1 | 75,394 | 11 | 150,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,m=kk()
ps,bs=ll(),ll()
b=c=0
for a in range(n):
while b<m and bs[b]<ps[a]: b+=1
if b==m:c+=1
else:b+=1
print(c)
``` | instruction | 0 | 75,395 | 11 | 150,790 |
Yes | output | 1 | 75,395 | 11 | 150,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
# Method 1:
# n, m = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
# b = list(map(int, input().split(' ')))
#
# i = j = 0
# while i < n and j < m:
# if b[j] >= a[i]:
# i += 1
# j += 1
# else:
# j += 1
# print(n - i)
# Method 2:
def inp():
return map(int, input().split())
n, m = inp()
a = list(inp())
b = list(inp())
count = 0
j = 0
for i in range(n):
while j < m:
if b[j] >= a[i]:
count += 1
j += 1
break
else:
j += 1
print(n - count)
'''
Note:
Example:
3 5
1 2 3
1 1 1 4 5
while i < n and j < m (stopping condition)
if b[j] >= a[i]:
i ++
j ++
else:
j ++
ans = n - i
time complexity: O(m) vì chỉ có mỗi biến j tăng sau mỗi vòng lặp
- why use 2 pointers:
+ 2 mảng đã đc sắp xếp
+ 2 biến chạy, ko cần reset biến chạy sau mỗi vòng lặp
'''
``` | instruction | 0 | 75,396 | 11 | 150,792 |
Yes | output | 1 | 75,396 | 11 | 150,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [0]* len(A)
for i in range(len(A)):
C[i] = A[i]
A.sort()
B.sort()
k = 0
def search_index(x, A):
# ищет левый индекс максимально близкого и меньшего или равного числу x
l = -1
r = len(A)
while r - l > 1:
m = int((l + r) / 2)
if A[m] <= x:
l = m
else:
r = m
return l
i = len(A) - 1
j = len(B) - 1
if len(B) >= len(A):
while i > -1 and j > -1:
if B[j] < A[i]:
k += 1
i -= 1
j -= 1
if j == -1 and i > 0:
k += i+1
else:
k = len(A)
q = len(A)
for y in range(len(B)-1,-1,-1):
w = search_index(B[y],A[:q])
q = w
if w == -1:
break
else:
k -= 1
print(k)
``` | instruction | 0 | 75,397 | 11 | 150,794 |
No | output | 1 | 75,397 | 11 | 150,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
#Problem 1 George & Round
first = input('').split()
n = int(first[0])
m = int(first[1])
listA = list(map(int,input('').split()))
listB = list(map(int,input('').split()))
count = 0
for i in range(0, len(listA)):
if listA[i] not in listB:
count += 1
print(count)
``` | instruction | 0 | 75,398 | 11 | 150,796 |
No | output | 1 | 75,398 | 11 | 150,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n, m = map(int, input().split())
ns = set(map(int, input().split()))
bs = set(map(int, input().split()))
print(n - len(ns & bs))
``` | instruction | 0 | 75,399 | 11 | 150,798 |
No | output | 1 | 75,399 | 11 | 150,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.
To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.
Output
Print a single integer — the answer to the problem.
Examples
Input
3 5
1 2 3
1 2 2 3 3
Output
0
Input
3 5
1 2 3
1 1 1 1 1
Output
2
Input
3 1
2 3 4
1
Output
3
Note
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
Submitted Solution:
```
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = set(b)
a = set(a)
z = c.intersection(a)
if(n<m):
print(abs(n-m))
else:
print(n-len(z))
``` | instruction | 0 | 75,400 | 11 | 150,800 |
No | output | 1 | 75,400 | 11 | 150,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
n, e = map(int, input().split())
r = list(map(int, input().split()))
d = [0] * n
for ee in range(e):
x, y = map(int, input().split())
x -= 1; y -= 1
if r[x] == r[y]: continue
if r[x] < r[y]: x, y = y, x
d[x] += 1
inds = sorted(range(n), key = lambda i: r[i])
j = 0
ans = [0] * n
for i in inds:
while r[inds[j]] < r[i]: j += 1
ans[i] = j - d[i]
print(*ans)
``` | instruction | 0 | 75,635 | 11 | 151,270 |
Yes | output | 1 | 75,635 | 11 | 151,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
import bisect
n,k = map(int,input().split())
r = list(map(int,input().split()))
t = sorted(r)
l = [0] * n
for i in range(k):
a,b = map(int,input().split())
a -= 1
b -= 1
if r[a] > r[b]:
l[a] += 1
elif r[a] < r[b]:
l[b] += 1
for i in range(n):
print(bisect.bisect_left(t,r[i]) - l[i],end=' ')
``` | instruction | 0 | 75,636 | 11 | 151,272 |
Yes | output | 1 | 75,636 | 11 | 151,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
from collections import defaultdict
from collections import Counter
n,k = map(int,input().split())
r = list(map(int,input().split()))
D = defaultdict(lambda : 0)
for i in range(k) :
a,b = map(int,input().split())
if D[a-1] == 0 :
D[a-1] = {b-1}
else :
D[a-1].add(b-1)
if D[b-1] == 0 :
D[b-1] = {a-1}
else :
D[b-1].add(a-1)
P = Counter(r)
g = sorted(range(n),key = lambda x:r[x],reverse = True )
i = 0
out = []
while(i < n -1) :
s = n - 1 - i - (P[r[g[i]]] - 1)
P[r[g[i]]] -= 1
if D[g[i]] != 0 :
for el in D[g[i]] :
if r[el] < r[g[i]] :
s -= 1
out.append([g[i],s])
i += 1
out.append([g[n-1],0])
out = sorted(out, key = lambda x:x[0])
t = [out[i][1] for i in range(n)]
print(*t,sep = ' ')
``` | instruction | 0 | 75,637 | 11 | 151,274 |
Yes | output | 1 | 75,637 | 11 | 151,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
n,k=map(int,input().split())
r=list(map(int,input().split()))
h=[0]*n
for _ in range(k):
a,b=map(int,input().split())
if r[a-1]<r[b-1]:h[b-1]+=1
if r[b-1]<r[a-1]:h[a-1]+=1
x=[[r[i],i] for i in range(n)]
x.sort()
o=['0']*n
u=0
for i in range(1, n):
if x[i][0]!=x[i-1][0]:
u=i
o[x[i][1]]=str(max(0,u-h[x[i][1]]))
print(' '.join(o))
``` | instruction | 0 | 75,638 | 11 | 151,276 |
Yes | output | 1 | 75,638 | 11 | 151,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
r = []
r2 = []
c = 0
for i in input().split():
m = [int(i), c]
r2.append(m)
r.append(m)
c += 1
r2.sort()
s = [0] * n
for i in range(n):
if i == 0:
None
elif r2[i][0] == r2[i - 1][0]:
s[r2[i][1]] = s[r2[i - 1][1]]
else:
s[r2[i][1]] = i
for i in range(k):
x, y = [int(i) for i in input().split()]
if r[x - 1] > r[y - 1]:
if s[x - 1] > 0:
s[x - 1] -= 1
elif r[x - 1] < r[y - 1]:
if s[y - 1] > 0:
s[y - 1] -= 1
print(*s)
``` | instruction | 0 | 75,639 | 11 | 151,278 |
No | output | 1 | 75,639 | 11 | 151,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
n,k=map(int,input().split())
q=[[] for i in range(n)]
skills=list(map(int,input().split()))
for i in range(k):
a,b=map(int,input().split())
q[a-1].append(b-1)
for i in range(n):
count=0
for j in range(n):
if(skills[i]>skills[j] and j not in q[i]):
count+=1
print(count,end=' ')
``` | instruction | 0 | 75,640 | 11 | 151,280 |
No | output | 1 | 75,640 | 11 | 151,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In BerSoft n programmers work, the programmer i is characterized by a skill r_i.
A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.
You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.
Input
The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.
Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.
Output
Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
Examples
Input
4 2
10 4 10 15
1 2
4 3
Output
0 0 1 2
Input
10 4
5 4 1 5 4 3 7 1 2 5
4 6
2 1
10 8
3 5
Output
5 4 0 5 3 3 9 0 2 5
Note
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.
Submitted Solution:
```
params = [int(s) for s in input().split(" ")]
n = params[0]
k = params[1]
skills = [int(s) for s in input().split(" ")]
indexes_sorted= [b[0] for b in sorted(enumerate(skills),key=lambda i:i[1])]
bad_relations={}
for i in range(k):
items = [int(s) for s in input().split(" ")]
first = items[0] - 1
second= items[1] - 1
if skills[first] > skills[second]:
bad_relations[first] = bad_relations.get(first, 0) + 1
elif skills[second]> skills[first]:
bad_relations[second] = bad_relations.get(first, 0) + 1
num_the_same=0
results = {}
prev=None
for idx, index in enumerate(indexes_sorted):
skill = skills[index]
if skill==prev:
num_the_same+=1
else:
num_the_same=0
cnt = idx - num_the_same - bad_relations.get(index,0)
if cnt < 0:
cnt= 0
results[index]= cnt
prev= skill
final=''
for i in range(n):
final+=str((results[i])) + " "
print(final.strip())
``` | instruction | 0 | 75,641 | 11 | 151,282 |
No | output | 1 | 75,641 | 11 | 151,283 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.