message
stringlengths
2
22.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
145
109k
cluster
float64
9
9
__index_level_0__
int64
290
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition. Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day. There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total). As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days. Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n. Input The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. Output If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). Examples Input 4 1 2 1 2 Output YES Input 3 1 0 1 Output NO Note In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days. Submitted Solution: ``` input() p=0 for x in map(int, input().split()): if x<p: p=-1 break p^=x&1 print('YES' if p==0 else 'NO') ```
instruction
0
20,792
9
41,584
Yes
output
1
20,792
9
41,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition. Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day. There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total). As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days. Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n. Input The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. Output If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). Examples Input 4 1 2 1 2 Output YES Input 3 1 0 1 Output NO Note In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days. Submitted Solution: ``` n=int(input()) trains=list(map(int,input().split())) for i in range(n-1): z=trains[i] if z>=2: z=z%2 if z==1: z=0 trains[i+1]=trains[i+1]-1 trains[i]=z if trains[n-1]%2==0: ans='YES' else: ans='NO' if -1 in trains: ans='NO' print(ans) ```
instruction
0
20,793
9
41,586
Yes
output
1
20,793
9
41,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition. Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day. There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total). As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days. Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n. Input The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. Output If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). Examples Input 4 1 2 1 2 Output YES Input 3 1 0 1 Output NO Note In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) f=0 s=0 for i in range(n): if a[i]>2: f=1 break if a[i]==0 and s%2!=0: f=1 break else: s+=a[i] if f==1: print('NO') else: print('YES') ```
instruction
0
20,794
9
41,588
No
output
1
20,794
9
41,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition. Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day. There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total). As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days. Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n. Input The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. Output If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). Examples Input 4 1 2 1 2 Output YES Input 3 1 0 1 Output NO Note In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days. Submitted Solution: ``` n = int(input()) arr = [0 if int(num) == 0 else 2 if int(num) % 2 == 0 else 1 for num in input().split()] arr.append(0) for i in range(len(arr) - 1): if(arr[i] == 1 and arr[i+1] == 0): print('NO') exit() elif(arr[i] == 1 and arr[i+1] != 2): arr[i] -= 1 arr[i+1] -= 1 elif(arr[i] == 2): arr[i] = 0 print("YES") # 1 2 1 2 # 1 2 -> 0 1 # 2 2 -> 0 2 # 2 1 -> 0 1 # 1 1 -> 0 0 # 1 0 -> bad # 2 0 -> # 0 0 -> 0 0 # 0 1 -> 0 1 # 0 2 -> 0 2 ```
instruction
0
20,795
9
41,590
No
output
1
20,795
9
41,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition. Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day. There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total). As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days. Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n. Input The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. Output If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). Examples Input 4 1 2 1 2 Output YES Input 3 1 0 1 Output NO Note In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days. Submitted Solution: ``` n = input() m = input().split() hitung = 0 for i in m: hitung += int(i) if hitung%2 != 0: print("NO") else: if set(m) == {"0"}: print("NO") elif "0" in m: counter = 0 itung = 0 while counter < len(m): itung += int(m[counter]) if int(m[counter]) == 0: if itung%2 == 0: itung = 0 counter += 1 else: print("NO") break else: counter += 1 if counter == len(m)-1: if itung%2 == 0: print("YES") else: print("NO") else: print("YES") ```
instruction
0
20,796
9
41,592
No
output
1
20,796
9
41,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition. Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day. There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total). As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days. Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n. Input The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. Output If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). Examples Input 4 1 2 1 2 Output YES Input 3 1 0 1 Output NO Note In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample. In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days. Submitted Solution: ``` n = int(input()) l= list(map(int, input().split())) if 0 in l: print("NO") exit() flag = 1 for i in range(1,n): a = l[i-1] b = l[i] if a%2==0 and b%2==0: continue elif a % 2 == 1 and b % 2 == 1: b = b-1 elif a % 2 == 0 and b % 2 == 1: continue else: b = b-1 if a==0 or b==0: flag = 0 break if flag ==0 or l[-1]%2==1: print("NO") else: print("YES") ```
instruction
0
20,797
9
41,594
No
output
1
20,797
9
41,595
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,962
9
41,924
"Correct Solution: ``` import math N, K = map(int, input().split()) A = sorted([int(i) for i in input().split()], reverse=True) F = sorted([int(i) for i in input().split()]) OK = 10**12 NG = -1 while OK-NG > 1: mid = (OK+NG)//2 cnt = 0 for a, f in zip(A, F): if a*f > mid: cnt += math.ceil((a*f-mid)/f) if cnt <= K: OK = mid else: NG = mid print(OK) ```
output
1
20,962
9
41,925
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,963
9
41,926
"Correct Solution: ``` n,k = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) l,r = 0,10**12+1 while l <r: mid = (l+r)//2 cnt = 0 for a,f in zip(A,F): cnt += max(0,a-mid//f) if cnt <=k: r = mid else: l = mid+1 print(l) ```
output
1
20,963
9
41,927
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,964
9
41,928
"Correct Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) left, right = -1, a[-1] * f[0] while right - left > 1: mid = (left + right) // 2 ck = 0 for i in range(n): ck += max(0, a[i] - mid // f[i]) if ck <= k: right = mid else: left = mid print(right) ```
output
1
20,964
9
41,929
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,965
9
41,930
"Correct Solution: ``` n,k=map(int,input().split()) abilities=sorted(list(map(int,input().split()))) foods=sorted(list(map(int,input().split())),reverse=True) if sum(abilities)<=k: print(0) exit() def check(score): ret=0 for a,f in zip(abilities,foods): ret+=max(0,(a*f-score+f-1)//f) return ret<=k ok=10**12+1 ng=0 for _ in range(50): mid=(ok+ng)//2 if check(mid): ok=mid else: ng=mid print(ok) ```
output
1
20,965
9
41,931
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,966
9
41,932
"Correct Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) f=list(map(int,input().split())) a.sort() f.sort(reverse=True) hi=10**12 lo=0 def c(mi): tmp=0 for i,j in zip(a,f): if mi//j<i: tmp+=i-mi//j if tmp<=k: return True return False while hi>=lo: mi=(hi+lo)//2 if c(mi): hi=mi-1 else: lo=mi+1 print(lo) ```
output
1
20,966
9
41,933
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,967
9
41,934
"Correct Solution: ``` import math (n,k),a,f = [list(map(int, s.split())) for s in open(0)] a.sort(reverse=True) f.sort() low = 0 high = 0 for x, y in zip(a,f): high = max(high, x*y) while high != low: test = int((high + low) // 2) tmp = 0 for x, y in zip(a,f): tmp += max(0, x - math.floor(test / y)) if tmp > k: low = test + 1 break else: high = test print(high) ```
output
1
20,967
9
41,935
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,968
9
41,936
"Correct Solution: ``` N, K = map(int, input().split()) As = list(map(int, input().split())) Fs = list(map(int, input().split())) As.sort() Fs.sort(reverse=True) def check(x): k = 0 for i in range(N): k += max(0, As[i]-x//Fs[i]) return k <= K a = 0 b = As[-1]*Fs[0] while a < b: i = (a + b)//2 if check(i): b = i else: if a == i: break a = i r = b print(r) ```
output
1
20,968
9
41,937
Provide a correct Python 3 solution for this coding contest problem. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12
instruction
0
20,969
9
41,938
"Correct Solution: ``` import math N,K=map(int,input().split()) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])] m,M,i=0,10**12,1 exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);"*50) print(M) ```
output
1
20,969
9
41,939
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` n,k = map(int,input().split()) A = sorted(list(map(int,input().split()))) F = sorted(list(map(int,input().split())),reverse=True) low = -1 high = 10**12 while high - low > 1: score = (low+high)//2 training = 0 for i in range(n): if A[i]*F[i] > score: training += A[i] - score//F[i] if training <= k: high = score else: low = score print(high) ```
instruction
0
20,970
9
41,940
Yes
output
1
20,970
9
41,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` import math N,K=map(int,input().split()) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])] min_i, max_i, index = 0, 10**12, 1 while True: index, max_i, min_i = ((index-1 + min_i)//2, index-1, min_i) if sum(math.ceil(max(0,c-index)/b)for b, c in X)<=K else((index+1 + max_i)//2, max_i, index+1) if min_i > max_i: print(min_i) break ```
instruction
0
20,971
9
41,942
Yes
output
1
20,971
9
41,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` N,K=map(int,input().split()) A=sorted(map(int,input().split())) F=sorted(map(int,input().split()),reverse=True) l=-1 r=A[-1]*F[0] while l+1<r: x=(l+r)//2 cnt=0 for i in range(N): cnt+=max(A[i]-x//F[i],0) if cnt<=K: r=x else: l=x print(r) ```
instruction
0
20,972
9
41,944
Yes
output
1
20,972
9
41,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` n,k=map(int,input().split()) a=sorted(list(map(int,input().split()))) #こっちは変えられない f=sorted(list(map(int,input().split())),reverse=True) l,r=0,10**12 def cal(x): global n,f,a,k ret=0 for i in range(n): ret+=max(0,a[i]-(x//f[i])) #print(ret,x) return ret while l+1<r: x=l+(r-l)//2 if cal(x)<=k: r=x else: l=x if cal(l)<=k: print(l) else: print(r) ```
instruction
0
20,973
9
41,946
Yes
output
1
20,973
9
41,947
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` n,k = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort() f.sort(reverse = True) def is_ok(t): cost = 0 for aa,ff in zip(a,f): temp = t // ff if temp >= aa: contninue cost += aa - temp if cost <= k: return True return False left = 0 right = a[-1]*f[0] while left < right: mid = (left + right) // 2 if is_ok(mid): right = mid else: left = mid + 1 print(left) ```
instruction
0
20,974
9
41,948
No
output
1
20,974
9
41,949
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` n,k = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort(reverse=True) f.sort() z = zip(a,f) ok = max(x*y for x,y in z) ng = -1 while ok-ng>1: mid = (ok+ng)//2 if sum(max(0,x-mid//y) for x,y in z) <= k: ok = mid else: ng = mid print(ok) ```
instruction
0
20,975
9
41,950
No
output
1
20,975
9
41,951
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` def resolve(): N,K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) import heapq q = [((-1)*A[i]*F[i],A[i],F[i]) for i in range(N)] heapq.heapify(q) for _ in range(K): s,a,f = q[0] if s == 0: break heapq.heappushpop(q,((a-1)*f*(-1),a-1,f)) print(q[0][0]*(-1)) resolve() ```
instruction
0
20,976
9
41,952
No
output
1
20,976
9
41,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows: * A team should assign one member to each food, and should not assign the same member to multiple foods. * It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. * The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints * All values in input are integers. * 1 \leq N \leq 2 \times 10^5 * 0 \leq K \leq 10^{18} * 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) * 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Examples Input 3 5 4 2 1 2 3 1 Output 2 Input 3 8 4 2 1 2 3 1 Output 0 Input 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Output 12 Submitted Solution: ``` N,K=map(int,input().split()) A=list(map(int,input().split())) F=list(map(int,input().split())) A=sorted(A,reverse=True) F=sorted(F) for i in range(len(A)): if K>0: if A[i]-K<0: K=K-A[i] A[i]=0 else: A[i]=A[i]-K K=K-A[i] A=sorted(A,reverse=True) print(max([x * y for (x, y) in zip(A, F)])) ```
instruction
0
20,977
9
41,954
No
output
1
20,977
9
41,955
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,106
9
42,212
"Correct Solution: ``` #!/usr/bin/python3 import os import sys def main(): L, K = read_ints() print(solve(L, K)) def solve(L, K): D = [[0, 0] for _ in range(L + 1)] D[1][0] = 1 if K <= L: D[K][0] = 1 for i in range(1, L): D[i + 1][1] += D[i][0] D[i + 1][0] += D[i][1] if i + K <= L: D[i + K][0] += D[i][1] return sum([D[i][0] for i in range(1, L + 1)]) ############################################################################### DEBUG = 'DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def dprint(*value, sep=' ', end='\n'): if DEBUG: print(*value, sep=sep, end=end) if __name__ == '__main__': main() ```
output
1
21,106
9
42,213
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,107
9
42,214
"Correct Solution: ``` import sys input = sys.stdin.readline def main(): l, k = map(int, input().split()) dp = [[0] * 2 for i in range(101)] dp[0][1] = 1 ans = 0 for i in range(1, l+1): dp[i][0] = dp[i-1][1] if i-k >= 0: dp[i][0] += dp[i-k][1] dp[i][1] = dp[i-1][0] ans += dp[i][0] print(ans) if __name__ == "__main__": main() ```
output
1
21,107
9
42,215
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,108
9
42,216
"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**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 = [] def f(l,k): r = [0] * (l+1) r[1] = 1 if l >= k: r[k] += 1 for i in range(1,l): if i + 2 <= l: r[i+2] += r[i] if i + 1 + k <= l: r[i+1+k] += r[i] return sum(r) while 1: n,m = LI() if n == 0: break rr.append(f(n,m)) break return '\n'.join(map(str, rr)) print(main()) ```
output
1
21,108
9
42,217
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,109
9
42,218
"Correct Solution: ``` l,k = map(int,input().split()) dp = [[0,0] for i in range(l+1)] dp[1][0] = 1 if k <= l: dp[k][0] = 1 for h in range(1,l): dp[h+1][0] += dp[h][1] dp[h+1][1] += dp[h][0] if h+k <= l: dp[h+k][1] += dp[h][0] ans = 0 for b,w in dp: ans += b print(ans) ```
output
1
21,109
9
42,219
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,110
9
42,220
"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(): n,k = LI() ans = 0 for l in range(1,n+1): for i in range(1000): if i*k > l:break j = l-i*k+i if j%2: j //= 2 j += 1 s = 1 for a in range(i): s *= j-a s //= a+1 ans += s print(ans) return #B def B(): 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__": A() ```
output
1
21,110
9
42,221
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,111
9
42,222
"Correct Solution: ``` l, k = map(int, input().split()) memo = {(l, 0): 1, (l, 1): 0} def dfs(cur, dark): if (cur, dark) in memo: return memo[cur, dark] res = dfs(cur + 1, dark^1) + (dark^1) if dark and cur + k <= l: res += dfs(cur + k, dark^1) memo[cur, dark] = res return res print(dfs(0, 1)) ```
output
1
21,111
9
42,223
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,112
9
42,224
"Correct Solution: ``` l , k = [int(i) for i in input().split()] INIT = 0 tableB = [INIT] * 110 tableW = [INIT] * 110 tableW[0] = 1 for i in range(1,l+1): tableB[i] += tableW[i-1] if i - k >= 0: tableB[i] += tableW[i-k] tableW[i+1] = tableB[i] print(sum(tableB)) #print(tableB) ```
output
1
21,112
9
42,225
Provide a correct Python 3 solution for this coding contest problem. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6
instruction
0
21,113
9
42,226
"Correct Solution: ``` import math l, k = map(int, input().split()) c = 0 for i in range(1, int((l + 1) / 2) + 1): for j in range(i + 1): if 2 * i - 1 + j * (k - 1) <= l: c += math.factorial(i) / math.factorial(j) / math.factorial(i - j) else: break print(int(c)) ```
output
1
21,113
9
42,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6 Submitted Solution: ``` l, k = map(int, input().split()) dpW = [0] * 101 dpB = [0] * 101 dpW[0] = 1 ans = 0 for i in range(1, l + 1): if i >= k: dpB[i] += dpW[i - k] ans += dpW[i - k] dpB[i] += dpW[i - 1] dpW[i] += dpB[i - 1] ans += dpW[i - 1] print(ans) ```
instruction
0
21,114
9
42,228
Yes
output
1
21,114
9
42,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6 Submitted Solution: ``` from functools import lru_cache # おまじない l,k=map(int,input().split()) @lru_cache() # python 素晴らしい def rec(i,isBlack): if i < 0: return 0 if i == 0: return 1 if not isBlack else 0 # black at bottom if isBlack: # top is black return rec(i-1, False) + rec(i-k, False) else: # top is white return rec(i-1, True) ans = sum ( rec(i,True) for i in range(1, l+1)) print(ans) ```
instruction
0
21,115
9
42,230
Yes
output
1
21,115
9
42,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. * A pole should consist of at least one disk. * The total thickness of disks in a pole should be less than or equal to $l$ cm. * The top disk and the bottom disk of a pole should be dark. * A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. <image> Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670 Example Input 5 3 Output 6 Submitted Solution: ``` import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def main(): l = list(map(int, input().split())) combinate_a = [] combinate_b = [] ans = 0 for a in range(l[0]): for b in range(l[0]): if (l[1] + 1) * a + 2 * b <= l[0] + 1: combinate_a.append(a) combinate_b.append(b) if (l[1] + 1) * a + 2 * b > l[0] + 1: break for i in range(1, len(combinate_a)): if combinate_a[i] == 0: ans += 1 else: ans += combinations_count(combinate_a[i]+combinate_b[i], combinate_a[i]) print(ans) if __name__ == '__main__': main() ```
instruction
0
21,116
9
42,232
No
output
1
21,116
9
42,233
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,788
9
43,576
"Correct Solution: ``` # -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62-1 EPS = 1.0e-8 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap class Circle: def __init__(self, x, y, r): self.x = x self.y = y self.r = r def center(self): return Point(self.x, self.y) def intersection(self, c): d = self.center().distance(c.center()) if d > self.r + c.r: return None # One circle within other if d < abs(self.r - c.r): return None # coincident circles if d == 0 and self.r == c.r: return None else: a = (self.r**2 - c.r**2 + d**2) / (2*d) h = math.sqrt(self.r**2-a**2 + sys.float_info.epsilon) x2 = self.x+a*(c.x-self.x)/d y2 = self.y+a*(c.y-self.y)/d x3 = x2+h*(c.y-self.y)/d y3 = y2-h*(c.x-self.x)/d x4 = x2-h*(c.y-self.y)/d y4 = y2+h*(c.x-self.x)/d return Point(x3, y3), Point(x4, y4) class Point: def __init__(self, x, y): self.x = x self.y = y def distance(self, p): return math.sqrt((self.x - p.x)**2 + (self.y - p.y)**2) class Bisect: def __init__(self, func): self.__func = func def bisect_left(self, x, lo, hi): while hi - lo > EPS: mid = (lo+hi)/2 if self.__func(mid) < x: lo = mid else: hi = mid return lo @mt def slv(N, K, XYC): def f(t): cs = [] for x, y, c in XYC: cs.append(Circle(x, y, t / c)) cand = [c.center() for c in cs] for i, j in combinations(range(N), r=2): p = cs[i].intersection(cs[j]) if p: cand.append(p[0]) cand.append(p[1]) ans = 0 for p in cand: tmp = 0 for c in cs: d = c.center().distance(p) if d - EPS < c.r: tmp += 1 ans = max(ans, tmp) return ans b = Bisect(f) return b.bisect_left(K, 0, 10000000) def main(): N, K = read_int_n() XYC = [read_int_n() for _ in range(N)] print(slv(N, K, XYC)) if __name__ == '__main__': main() ```
output
1
21,788
9
43,577
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,789
9
43,578
"Correct Solution: ``` import sys readline = sys.stdin.buffer.readline EPS = 1e-7 class Circle: def __init__(self, cx, cy, r): self.center = (cx, cy) self.radius = r def cross(self, C2): x1, y1 = self.center x2, y2 = C2.center R1 = self.radius R2 = C2.radius if (R2-R1)**2 + EPS <= (x2-x1)**2 + (y2-y1)**2 <= (R2+R1)**2 - EPS: dx, dy = x2-x1, y2-y1 a = (R2**2 - R1**2 + x1**2 - x2**2 + y1**2 - y2**2)/2 if abs(dy) > EPS: #交点はdx*X + dy*Y + a = 0 上 D = dx**2 + dy**2 bx = a*dx+dx*dy*y1-x1*dy**2 cx = dy**2*(x1**2-R1**2) + (a+dy*y1)**2 cx1 = (-bx + (bx**2-D*cx)**0.5)/D cx2 = (-bx - (bx**2-D*cx)**0.5)/D cy1 = -(dx*cx1+a)/dy cy2 = -(dx*cx2+a)/dy else: k = (R1**2-R2**2+dx**2)/2/dx cx1 = cx2 = x1+k cy1 = y1 + (R1**2-k**2)**0.5 cy2 = y1 - (R1**2-k**2)**0.5 return [(cx1, cy1), (cx2, cy2)] else: return [] def isinside(self, x, y): x1, y1 = self.center return (x1-x)**2 + (y1-y)**2 - EPS < self.radius**2 N, K = map(int, readline().split()) Points = [tuple(map(int, readline().split())) for _ in range(N)] ok = 1e6 ng = 0 candidate = [(x, y) for x, y, _ in Points] for _ in range(40): med = (ok+ng)/2 Cs = [Circle(x, y, med/c) for x, y, c in Points] candidate2 = candidate[:] for i in range(N): for j in range(i): candidate2.extend(Cs[i].cross(Cs[j])) for px, py in candidate2: res = 0 for C in Cs: if C.isinside(px, py): res += 1 if res >= K: ok = med break else: ng = med print(ok) ```
output
1
21,789
9
43,579
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,790
9
43,580
"Correct Solution: ``` import sys # input = sys.stdin.readline input = sys.stdin.buffer.readline import math from itertools import combinations EPS = 10**-7 class P2(): def __init__(self, x, y): self.x = x self.y = y self.norm2 = (self.x**2 + self.y**2)**0.5 def __add__(self, other): return P2(self.x + other.x, self.y + other.y) def __sub__(self, other): return P2(self.x - other.x, self.y - other.y) def __mul__(self, other: float): return P2(self.x * other, self.y * other) def __truediv__(self, other: float): return P2(self.x / other, self.y / other) def dot(self, other): return self.x * other.x + self.y * other.y def det(self, other): return self.x * other.y - self.y * other.x class Circle(): def __init__(self, p, r): self.p = p self.r = r n, k = map(int, input().split()) p = [] c = [] for _ in range(n): x, y, cc = map(float, input().split()) p.append(P2(x, y)) c.append(cc) dist = [[(p[i] - p[j]).norm2 for j in range(n)] for i in range(n)] def check(r): circles = [Circle(p[i], r / c[i]) for i in range(n)] # 半径rの円2つの交点の列挙 cand = [pi for pi in p] for c_i, c_j in combinations(circles, r=2): d_ij = c_i.p - c_j.p if d_ij.norm2 < c_i.r + c_j.r - EPS: # 点iと点jを中心とする円が交点を持つ時 x = (c_j.r**2 - c_i.r**2 + d_ij.norm2**2) / (2 * d_ij.norm2) h = math.sqrt(max(c_j.r**2 - x**2, 0.0)) v = P2(-d_ij.y, d_ij.x) * (h / d_ij.norm2) dx = c_j.p + d_ij * (x / d_ij.norm2) cand.append(dx + v) cand.append(dx - v) for cand_p in cand: cnt = 0 for c_i in circles: if (c_i.p - cand_p).norm2 < c_i.r + EPS: cnt += 1 if cnt >= k: return True return False lb = 0.0 # False ub = 3000 * 100 # True while ub - lb > EPS: mid = (ub + lb) / 2 if check(mid): ub = mid else: lb = mid print(ub) ```
output
1
21,790
9
43,581
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,791
9
43,582
"Correct Solution: ``` #!/usr/bin/env python3 import sys import cmath import math import copy INF = float("inf") EPS = 1e-9 def ctc(p1, r1, p2, r2): # 二つの円の共通接線の数 # common tangent count? # common tangent of circle? # 2円の関係性は、 # 同一(=INF), 離れている(=4)、外接(=3)、交わる(=2)、内接(=1)、内包(=0)がある # r1 <= r2として一般性を失わない if r2 < r1: p1, p2 = p2, p1 r1, r2 = r2, r1 d = abs(p1-p2) if p1 == p2 and d < EPS: # 同一の円 return INF elif (d - (r2+r1)) > EPS: # 離れている return 4 elif (d - (r2+r1)) > -EPS: # 外接している return 3 elif (d-(r2-r1)) > EPS: # 交わっている return 2 elif (d-(r2-r1)) > -EPS: # 内接している return 1 else: # 内包している return 0 def inner(p1, c1, p2, c2): coeff1 = c1/(c1+c2) coeff2 = c2/(c1+c2) return p1*coeff1+p2*coeff2 def intersection(p1, r1, p2, r2): status = ctc(p1, r1, p2, r2) d = abs(p1-p2) if not (1 <= status <= 3): return [] elif status == 3: # 外接 return [inner(p1, r1, p2, r2)] elif status == 1: # 内接 return [p1 + r1*(p1-p2)/d] else: # 交わっている場合 if r1 > r2: p1, p2 = p2, p1 r1, r2 = r2, r1 d = abs(p1-p2) cos = (r1**2+d**2-r2**2)/(2*r1*d) angle = math.acos(cos) phi = cmath.phase(p2-p1) return [ p1 + cmath.rect(r1, phi+angle), p1 + cmath.rect(r1, phi-angle) ] def circle_in(p, o, r1, allow_on_edge=True): if allow_on_edge: return abs(o-p)-r1 < EPS else: return abs(o-p)-r1 < -EPS def solve(N: int, K: int, x: "List[int]", y: "List[int]", c: "List[int]"): # 時刻Tの時点でK枚以上の肉が焼ける熱源の配置はあるか comp = [complex(xx, yy) for xx, yy in zip(x, y)] left = 0 right = 2000*max(c) while right - left > EPS: mid = (left + right)/2 yakiniku = 0 b = copy.copy(comp) for i in range(N): for j in range(i+1, N): b.extend(intersection(comp[i], mid/c[i], comp[j], mid/c[j])) for p in b: count = [circle_in(p, comp[k], mid/c[k]) for k in range(N)] yakiniku = max(yakiniku, sum(count)) if yakiniku >= K: right = mid else: left = mid print(mid) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int x = [int()] * (N) # type: "List[int]" y = [int()] * (N) # type: "List[int]" c = [int()] * (N) # type: "List[int]" for i in range(N): x[i] = int(next(tokens)) y[i] = int(next(tokens)) c[i] = int(next(tokens)) solve(N, K, x, y, c) if __name__ == '__main__': main() ```
output
1
21,791
9
43,583
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,792
9
43,584
"Correct Solution: ``` N,K = map(int,input().split()) XYC = [tuple(map(int,input().split())) for i in range(N)] from math import hypot,acos,atan2,cos,sin def circles_cross_points(x1,y1,r1,x2,y2,r2): d = hypot(x1-x2, y1-y2) if r1 + r2 < d or abs(r1 - r2) >= d: return [] x = (r1**2 + d**2 - r2**2) / (2*r1*d) if not -1 <= x <= 1: return [] a = acos(x) t = atan2(y2-y1, x2-x1) return [ (x1+cos(t+a)*r1, y1+sin(t+a)*r1), (x1+cos(t-a)*r1, y1+sin(t-a)*r1) ] eps = 10e-10 def is_ok(t): cands = [] for x,y,_ in XYC: cands.append((x,y)) for i,(x1,y1,c1) in enumerate(XYC[:-1]): for x2,y2,c2 in XYC[i+1:]: ps = circles_cross_points(x1,y1,t/c1,x2,y2,t/c2) cands += ps for cx,cy in cands: k = 0 for x,y,c in XYC: d = hypot(cx-x,cy-y) if c*d <= t + eps: k += 1 if k >= K: return True return False ok = 10**10 ng = 0 for _ in range(100): m = (ok+ng)/2 if is_ok(m): ok = m else: ng = m if ok-ng < 10e-7: break print(ok) ```
output
1
21,792
9
43,585
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,793
9
43,586
"Correct Solution: ``` import math def intersectionCC0(x1, y1, r1, r2): r = x1**2 + y1**2 t = (r + r1**2 - r2**2) / (2*r) dd = r1**2/r - t**2 if - (10**-8) < dd < 0: dd = 0 if dd < 0: return [] x, y = t * x1, t * y1 if dd == 0: return [(x, y)] sq = math.sqrt(dd) dx, dy = y1 * sq, -x1 * sq return [(x+dx, y+dy), (x-dx, y-dy)] def intersectionCC(x1, y1, x2, y2, r1, r2): return [(x1+x, y1+y) for x, y in intersectionCC0(x2-x1, y2-y1, r1, r2)] def chk(t): L = [a for a in L0] for i, (x1, y1, c1) in enumerate(X): for x2, y2, c2 in X[:i]: L += intersectionCC(x1, y1, x2, y2, t/c1, t/c2) for x0, y0 in L: cnt = 0 for x, y, c in X: if math.sqrt((x-x0) ** 2 + (y-y0) ** 2) * c <= t + 10**-8: cnt += 1 if cnt >= K: return 1 return 0 N, K = map(int, input().split()) X = [] L0 = [] for _ in range(N): x, y, c = map(int, input().split()) X.append((x, y, c)) L0.append((x, y)) l, r = 0, 150000 while (r-l) * (1<<20) > max(1, l): m = (l+r) / 2 if chk(m): r = m else: l = m print((l+r)/2) ```
output
1
21,793
9
43,587
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,794
9
43,588
"Correct Solution: ``` import sys input = sys.stdin.buffer.readline n, k = map(int, input().split()) XY = [] C = [] kouho = [] for i in range(n): x, y, c = map(int, input().split()) XY.append((x, y)) C.append(c) kouho.append(complex(x, y)) ct = 100 eps = 10 ** (-7) class circle: def __init__(self, center, r): self.center = center self.r = r def circle_cross(c1, c2): r1 = c1.r o1 = c1.center r2 = c2.r o2 = c2.center d = abs(o1 - o2) if d > r1 + r2: return 0, 0, 0 elif r1 + r2 < d + eps and r1 + r2 > d - eps: # d==r1+r2 return 1, (r2 * o1 + r1 * o2) / (r1 + r2), 0 elif d < r1 + r2 and d > abs(r1 - r2): # abs(r1-r2)<d<r1+r2 o21 = o2 - o1 oh_nagasa = (d ** 2 + r1 ** 2 - r2 ** 2) / (2 * d) if oh_nagasa < eps: return 1, (r2 * o1 + r1 * o2) / (r1 + r2), 0 oh = oh_nagasa * (o21 / d) housen = (o21 / d) * complex(0, 1) suisen = max(0, (r1 ** 2 - oh_nagasa ** 2) ** (1 / 2)) ans1 = o1 + oh + housen * suisen ans2 = o1 + oh - housen * suisen return 2, ans1, ans2 elif abs(r1 - r2) > d - eps and abs(r1 - r2) < d + eps: # d=abs(r1-r2) ans = (-r2 * o1 + r1 * o2) / (r1 - r2) return 1, ans, 0 else: # d<abs(r1-r2) return 0, 0, 0 if n == 1: print(0) exit() if k == 1: print(0) exit() ok = 10 ** 10 ng = 0 while ct > 0: mid = (ok + ng) / 2 kouho_temp = kouho[::] for i in range(n - 1): a, b = XY[i] p = C[i] A = circle(complex(a, b), mid / p) for j in range(i + 1, n): c, d = XY[j] q = C[j] B = circle(complex(c, d), mid / q) t1, t2, t3 = circle_cross(A, B) if t1 == 0: continue if t1 == 1: kouho_temp.append(t2) if t1 == 2: kouho_temp.append(t2) kouho_temp.append(t3) res = 0 for z in kouho_temp: cnt = 0 for i in range(n): x, y = XY[i] p = C[i] z1 = complex(x, y) if abs(z - z1) < mid / p + eps: cnt += 1 res = max(cnt, res) if res >= k: ok = mid else: ng = mid ct -= 1 print(mid) ```
output
1
21,794
9
43,589
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252
instruction
0
21,795
9
43,590
"Correct Solution: ``` from math import atan2, cos, sin EPS = 1e-7 def hypot(a): return sum(x ** 2 for x in a) ** 0.5 def scale(s, v): assert isinstance(s, int) or isinstance(s, float) return [s * v[0], s * v[1], s * v[2]] def dot(a, b): return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] def add(a, b): return [a[0] + b[0], a[1] + b[1], a[2] + b[2]] def sub(a, b): return [a[0] - b[0], a[1] - b[1], a[2] - b[2]] def matmul(mat, v): return [dot(row, v) for row in mat] def rotZ(theta): return [[cos(theta), -sin(theta), 0], [sin(theta), cos(theta), 0], [0, 0, 1]] def _circleCircleIntersection(R, d, r): # For circles centered at (0, 0) and (d, 0) with radius R and r respectively # Equations are: # x^2 + y^2 = R^2 # (x - d)^2 + y^2 = r^2 # Subtracting and expanding: # x^2 - (x^2 - 2 * d * x + d^2) = R^2 - r^2 # 2 * d * x - d^2 = R^2 - r^2 # x = (R^2 - r^2 + d^2) / (2*d) if d == 0: return [(0, 0)] x = (R ** 2 - r ** 2 + d ** 2) / (2 * d) ySq = R ** 2 - x ** 2 if ySq == 0: return [(x, 0)] elif ySq > 0: y = ySq ** 0.5 # assert abs((x ** 2 + y ** 2) - R ** 2) < EPS # assert abs(((x - d) ** 2 + y ** 2) - r ** 2) < EPS return [(x, y), (x, -y)] else: raise AssertionError() def circleCircleIntersection(x1, y1, r1, x2, y2, r2): # Either 1 point, 2 points, or # 0 points because one circle contains the other # 0 points because the circles don't intersect v1 = [x1, y1, 0] v2 = [x2, y2, 0] d = hypot(sub(v2, v1)) if r1 + r2 < d: # Circles don't intersect return [] if min(r1, r2) + d < max(r1, r2): # One circle contains the other return [] # Translate offset = list(v1) v1 = sub(v1, offset) v2 = sub(v2, offset) assert v1[0] == 0 and v1[1] == 0 # Rotate angle = -atan2(v2[1], v2[0]) v2 = matmul(rotZ(angle), v2) assert abs(v2[1]) < EPS ret = [] for pt in _circleCircleIntersection(r1, v2[0], r2): pt = [pt[0], pt[1], 0] # Un-rotate pt = matmul(rotZ(-angle), pt) # Un-translate pt = add(pt, offset) ret.append((pt[0], pt[1])) return ret def circleCircleIntersection(x1, y1, r1, x2, y2, r2): # Alternative implementation v1 = [x1, y1, 0] v2 = [x2, y2, 0] d = hypot(sub(v2, v1)) if r1 + r2 < d: # Circles don't intersect return [] if min(r1, r2) + d < max(r1, r2): # One circle contains the other return [] if d == 0: return [(x1, y1)] # Unit vector in the direction between the centers u = scale(1 / d, sub(v2, v1)) # Distance from x1, y1 to the midpoint of the chord a = (r1 ** 2 - r2 ** 2 + d ** 2) / (2 * d) # Get the midpoint on the chord mid = add(v1, scale(a, u)) # Unit vector in direction of the chord uPerpendicular = [u[1], -u[0], 0] # 2 * h is the length of the chord h = (r1 ** 2 - a ** 2) ** 0.5 # Get the two solutions ret1 = add(mid, scale(h, uPerpendicular)) ret2 = add(mid, scale(-h, uPerpendicular)) return [[ret1[0], ret1[1]], [ret2[0], ret2[1]]] N, K = list(map(int, input().split())) XYC = [] for i in range(N): XYC.append(list(map(int, input().split()))) def numMeat(t): # At time t, each x, y can be heated by anything within a circle of radius radius t/c # Gather all intersecting points, some of which must be part of the region with most overlaps intersect = [] for i in range(len(XYC)): x1, y1, c1 = XYC[i] r1 = t / c1 for j in range(i + 1, len(XYC)): x2, y2, c2 = XYC[j] r2 = t / c2 pts = circleCircleIntersection(x1, y1, r1, x2, y2, r2) intersect.extend(pts) intersect.append((x1, y1)) if False: import matplotlib.pyplot as plt plt.figure() ax = plt.gca() ax.cla() bound = t // 5 ax.set_xlim((-bound, bound)) ax.set_ylim((-bound, bound)) for i in range(len(XYC)): x1, y1, c1 = XYC[i] r1 = t / c1 ax.add_artist(plt.Circle((x1, y1), r1, color="blue", fill=False)) for x, y in intersect: ax.plot([x], [y], ".", color="red") plt.show() best = 0 for pt in intersect: count = 0 for x, y, c in XYC: if c * ((x - pt[0]) ** 2 + (y - pt[1]) ** 2) ** 0.5 <= t + EPS: count += 1 best = max(best, count) return best lo = 0 # Get upperbound (by arbitrarily placing heat source at origin) hi = max(c * (x ** 2 + y ** 2) ** 0.5 for x, y, c in XYC) while hi - lo > EPS: mid = (hi + lo) / 2 if numMeat(mid) >= K: hi = mid else: lo = mid print(hi) ```
output
1
21,795
9
43,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` import cmath import itertools import math import os import random import sys INF = float("inf") PI = cmath.pi TAU = cmath.pi * 2 EPS = 1e-10 if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 class Point: """ 2次元空間上の点 """ # 反時計回り側にある CCW_COUNTER_CLOCKWISE = 1 # 時計回り側にある CCW_CLOCKWISE = -1 # 線分の後ろにある CCW_ONLINE_BACK = 2 # 線分の前にある CCW_ONLINE_FRONT = -2 # 線分上にある CCW_ON_SEGMENT = 0 def __init__(self, x: float, y: float): self.c = complex(x, y) @property def x(self): return self.c.real @property def y(self): return self.c.imag @staticmethod def from_complex(c: complex): return Point(c.real, c.imag) @staticmethod def from_polar(r: float, phi: float): c = cmath.rect(r, phi) return Point(c.real, c.imag) def __add__(self, p): """ :param Point p: """ c = self.c + p.c return Point(c.real, c.imag) def __iadd__(self, p): """ :param Point p: """ self.c += p.c return self def __sub__(self, p): """ :param Point p: """ c = self.c - p.c return Point(c.real, c.imag) def __isub__(self, p): """ :param Point p: """ self.c -= p.c return self def __mul__(self, f: float): c = self.c * f return Point(c.real, c.imag) def __imul__(self, f: float): self.c *= f return self def __truediv__(self, f: float): c = self.c / f return Point(c.real, c.imag) def __itruediv__(self, f: float): self.c /= f return self def __repr__(self): return "({}, {})".format(round(self.x, 10), round(self.y, 10)) def __neg__(self): c = -self.c return Point(c.real, c.imag) def __eq__(self, p): return abs(self.c - p.c) < EPS def __abs__(self): return abs(self.c) @staticmethod def ccw(a, b, c): """ 線分 ab に対する c の位置 線分上にあるか判定するだけなら on_segment とかのが速い Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja :param Point a: :param Point b: :param Point c: """ b = b - a c = c - a det = b.det(c) if det > EPS: return Point.CCW_COUNTER_CLOCKWISE if det < -EPS: return Point.CCW_CLOCKWISE if b.dot(c) < -EPS: return Point.CCW_ONLINE_BACK if b.dot(b - c) < -EPS: return Point.CCW_ONLINE_FRONT return Point.CCW_ON_SEGMENT def dot(self, p): """ 内積 :param Point p: :rtype: float """ return self.x * p.x + self.y * p.y def det(self, p): """ 外積 :param Point p: :rtype: float """ return self.x * p.y - self.y * p.x def dist(self, p): """ 距離 :param Point p: :rtype: float """ return abs(self.c - p.c) def norm(self): """ 原点からの距離 :rtype: float """ return abs(self.c) def phase(self): """ 原点からの角度 :rtype: float """ return cmath.phase(self.c) def angle(self, p, q): """ p に向いてる状態から q まで反時計回りに回転するときの角度 -pi <= ret <= pi :param Point p: :param Point q: :rtype: float """ return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c) + PI) % TAU - PI def area(self, p, q): """ p, q となす三角形の面積 :param Point p: :param Point q: :rtype: float """ return abs((p - self).det(q - self) / 2) def projection_point(self, p, q, allow_outer=False): """ 線分 pq を通る直線上に垂線をおろしたときの足の座標 Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A&lang=ja :param Point p: :param Point q: :param allow_outer: 答えが線分の間になくても OK :rtype: Point|None """ diff_q = q - p # 答えの p からの距離 r = (self - p).dot(diff_q) / abs(diff_q) # 線分の角度 phase = diff_q.phase() ret = Point.from_polar(r, phase) + p if allow_outer or (p - ret).dot(q - ret) < EPS: return ret return None def reflection_point(self, p, q): """ 直線 pq を挟んで反対にある点 Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&lang=ja :param Point p: :param Point q: :rtype: Point """ # 距離 r = abs(self - p) # pq と p-self の角度 angle = p.angle(q, self) # 直線を挟んで角度を反対にする angle = (q - p).phase() - angle return Point.from_polar(r, angle) + p def on_segment(self, p, q, allow_side=True): """ 点が線分 pq の上に乗っているか Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja :param Point p: :param Point q: :param allow_side: 端っこでギリギリ触れているのを許容するか :rtype: bool """ if not allow_side and (self == p or self == q): return False # 外積がゼロ: 面積がゼロ == 一直線 # 内積がマイナス: p - self - q の順に並んでる return abs((p - self).det(q - self)) < EPS and (p - self).dot(q - self) < EPS @staticmethod def circumcenter_of(p1, p2, p3): """ 外心 :param Point p1: :param Point p2: :param Point p3: :rtype: Point|None """ if abs((p2 - p1).det(p3 - p1)) < EPS: # 外積がゼロ == 一直線 return None # https://ja.wikipedia.org/wiki/外接円 a = (p2.x - p3.x) ** 2 + (p2.y - p3.y) ** 2 b = (p3.x - p1.x) ** 2 + (p3.y - p1.y) ** 2 c = (p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2 num = p1 * a * (b + c - a) + p2 * b * (c + a - b) + p3 * c * (a + b - c) den = a * (b + c - a) + b * (c + a - b) + c * (a + b - c) return num / den @staticmethod def incenter_of(p1, p2, p3): """ 内心 :param Point p1: :param Point p2: :param Point p3: """ # https://ja.wikipedia.org/wiki/三角形の内接円と傍接円 d1 = p2.dist(p3) d2 = p3.dist(p1) d3 = p1.dist(p2) return (p1 * d1 + p2 * d2 + p3 * d3) / (d1 + d2 + d3) class Circle: def __init__(self, o, r): """ :param Point o: :param float r: """ self.o = o self.r = r def __eq__(self, other): return self.o == other.o and abs(self.r - other.r) < EPS def ctc(self, c): """ 共通接線 common tangent の数 4: 離れてる 3: 外接 2: 交わってる 1: 内接 0: 内包 inf: 同一 Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_A&lang=ja :param Circle c: :rtype: int """ if self.o == c.o: return INF if abs(self.r - c.r) < EPS else 0 # 円同士の距離 d = self.o.dist(c.o) - self.r - c.r if d > EPS: return 4 elif d > -EPS: return 3 # elif d > -min(self.r, c.r) * 2: elif d + min(self.r, c.r) * 2 > EPS: return 2 elif d + min(self.r, c.r) * 2 > -EPS: return 1 return 0 def has_point_on_edge(self, p): """ 指定した点が円周上にあるか :param Point p: :rtype: bool """ return abs(self.o.dist(p) - self.r) < EPS def contains(self, p, allow_on_edge=True): """ 指定した点を含むか :param Point p: :param bool allow_on_edge: 辺上の点を許容するか """ if allow_on_edge: # return self.o.dist(p) <= self.r return self.o.dist(p) - self.r < EPS else: # return self.o.dist(p) < self.r return self.o.dist(p) - self.r < -EPS def area(self): """ 面積 """ return self.r ** 2 * PI def circular_segment_area(self, angle): """ 弓形⌓の面積 :param float angle: 角度ラジアン """ # 扇形の面積 sector_area = self.area() * angle / TAU # 三角形部分を引く return sector_area - self.r ** 2 * math.sin(angle) / 2 def intersection_points(self, other, allow_outer=False): """ :param Segment|Circle other: :param bool allow_outer: """ if isinstance(other, Segment): return self.intersection_points_with_segment(other, allow_outer=allow_outer) if isinstance(other, Circle): return self.intersection_points_with_circle(other) raise NotImplementedError() def intersection_points_with_segment(self, s, allow_outer=False): """ 線分と交差する点のリスト Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D&lang=ja :param Segment s: :param bool allow_outer: 線分の間にない点を含む :rtype: list of Point """ # 垂線の足 projection_point = self.o.projection_point(s.p1, s.p2, allow_outer=True) # 線分との距離 dist = self.o.dist(projection_point) # if dist > self.r: if dist - self.r > EPS: return [] if dist - self.r > -EPS: if allow_outer or s.has_point(projection_point): return [projection_point] else: return [] # 足から左右に diff だけ動かした座標が答え diff = Point.from_polar(math.sqrt(self.r ** 2 - dist ** 2), s.phase()) ret1 = projection_point + diff ret2 = projection_point - diff ret = [] if allow_outer or s.has_point(ret1): ret.append(ret1) if allow_outer or s.has_point(ret2): ret.append(ret2) return ret def intersection_points_with_circle(self, other): """ 円と交差する点のリスト Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E&langja :param circle other: :rtype: list of Point """ ctc = self.ctc(other) if not 1 <= ctc <= 3: return [] if ctc == 3: # 外接 return [Point.from_polar(self.r, (other.o - self.o).phase()) + self.o] if ctc == 1: # 内接 if self.r > other.r: return [Point.from_polar(self.r, (other.o - self.o).phase()) + self.o] else: return [Point.from_polar(self.r, (self.o - other.o).phase()) + self.o] # 2つ交点がある assert ctc == 2 a = other.r b = self.r c = self.o.dist(other.o) # 余弦定理で cos(a) を求めます cos_a = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c) angle = math.acos(cos_a) phi = (other.o - self.o).phase() return [ self.o + Point.from_polar(self.r, phi + angle), self.o + Point.from_polar(self.r, phi - angle), ] def tangent_points_with_point(self, p): """ p を通る接線との接点 :param Point p: :rtype: list of Point """ dist = self.o.dist(p) # if dist < self.r: if dist - self.r < -EPS: # p が円の内部にある return [] if dist - self.r < EPS: # p が円周上にある return [Point(p.x, p.y)] a = math.sqrt(dist ** 2 - self.r ** 2) b = self.r c = dist # 余弦定理で cos(a) を求めます cos_a = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c) angle = math.acos(cos_a) phi = (p - self.o).phase() return [ self.o + Point.from_polar(self.r, phi + angle), self.o + Point.from_polar(self.r, phi - angle), ] def tangent_points_with_circle(self, other): """ other との共通接線との接点 :param Circle other: :rtype: list of Point """ ctc = self.ctc(other) if ctc > 4: raise ValueError('2つの円が同一です') if ctc == 0: return [] if ctc == 1: return self.intersection_points_with_circle(other) assert ctc in (2, 3, 4) ret = [] # 共通外接線を求める # if self.r == other.r: if abs(self.r - other.r) < EPS: # 半径が同じ == 2つの共通外接線が並行 phi = (other.o - self.o).phase() ret.append(self.o + Point.from_polar(self.r, phi + PI / 2)) ret.append(self.o + Point.from_polar(self.r, phi - PI / 2)) else: # 2つの共通外接線の交点から接線を引く intersection = self.o + (other.o - self.o) / (self.r - other.r) * self.r ret += self.tangent_points_with_point(intersection) # 共通内接線を求める # 2つの共通内接線の交点から接線を引く intersection = self.o + (other.o - self.o) / (self.r + other.r) * self.r ret += self.tangent_points_with_point(intersection) return ret @staticmethod def circumscribed_of(p1, p2, p3): """ p1・p2・p3 のなす三角形の外接円 Verify: :param Point p1: :param Point p2: :param Point p3: """ if p1.on_segment(p2, p3): return Circle((p2 + p3) / 2, p2.dist(p3) / 2) if p2.on_segment(p1, p3): return Circle((p1 + p3) / 2, p1.dist(p3) / 2) if p3.on_segment(p1, p2): return Circle((p1 + p2) / 2, p1.dist(p2) / 2) o = Point.circumcenter_of(p1, p2, p3) return Circle(o, o.dist(p1)) @staticmethod def min_enclosing(points): """ points をすべて含む最小の円 計算量の期待値は O(N) https://www.jaist.ac.jp/~uehara/course/2014/i481f/pdf/ppt-7.pdf Verify: https://www.spoj.com/problems/QCJ4/ :param list of Point points: :rtype: Circle """ points = points[:] random.shuffle(points) # 前から順番に決めて大きくしていく ret = Circle(points[0], 0) for i, p in enumerate(points): if ret.contains(p): continue ret = Circle(p, 0) for j, q in enumerate(points[:i]): if ret.contains(q): continue # 2点を直径とする円 ret = Circle((p + q) / 2, abs(p - q) / 2) for k, r in enumerate(points[:j]): if ret.contains(r): continue # 3点に接する円 ret = Circle.circumscribed_of(p, q, r) return ret def argsort(li, key=None, reverse=False): return [i for _, i in sorted( [(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse )] N, K = list(map(int, sys.stdin.buffer.readline().split())) XYC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)] def test(t: float): # http://tottoripaper.hatenablog.jp/entry/2015/03/10/231142 # K こ以上の肉を焼けるか circles = [] for x, y, c in XYC: circles.append(Circle(Point(x, y), t /c)) # 交点 points = [] for c1, c2 in itertools.combinations(circles, r=2): points += c1.intersection_points_with_circle(c2) for c in circles: points.append(c.o) for p in points: cnt = 0 for c in circles: cnt += c.contains(p) if cnt >= K: return True return False # # # T: iとjが重なる時間 # T = [] # for i, j in itertools.combinations(range(N), r=2): # xi, yi, ci = XYC[i] # xj, yj, cj = XYC[j] # d = (xi - xj) ** 2 + (yi - yj) ** 2 # t = d / (ci + cj) # T.append((t, i, j)) # T.sort() # print(T) # ans = INF # for t, i, j in T: # xi, yi, ci = XYC[i] # xj, yj, cj = XYC[j] # p = Point(xi, yi) # q = Point(xj, yj) # test_p = Point.from_polar(ci * t, (q - p).phase()) # if test(test_p, t): # ans = t # break # print(ans) ok = 1 << 100 ng = 0 while abs(ok - ng) > EPS: mid = (ok + ng) / 2 if test(mid): ok = mid else: ng = mid print(ok) ```
instruction
0
21,796
9
43,592
Yes
output
1
21,796
9
43,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` #!/usr/bin/env python3 import sys input = sys.stdin.readline import math eps = 1e-12 def calc_intersection_points(circle0, circle1): x0, y0, r0 = circle0 x1, y1, r1 = circle1 d = math.hypot(x0 - x1, y0 - y1) if d > r0 + r1 or d < abs(r0 - r1): return [] ret = [] if r0 + r1 == d: a = r0 h = 0.0 else: a = (r0**2 - r1**2 + d**2) / (2.0 * d) h = math.sqrt(r0**2 - a**2) x2 = x0 + a * (x1 - x0) / d y2 = y0 + a * (y1 - y0) / d x3 = x2 + h * (y1 - y0) / d y3 = y2 - h * (x1 - x0) / d ret.append((x3, y3)) if h == 0: return ret x4 = x2 - h * (y1 - y0) / d y4 = y2 + h * (x1 - x0) / d ret.append((x4, y4)) return ret n, k = map(int, input().split()) niku = [] for _ in range(n): x, y, c = map(int, input().split()) niku.append((x, y, c)) l = 0.0; r = 10**8 for _ in range(64): mid = (l + r) / 2.0 circles = [] for x, y, c in niku: circles.append((x, y, mid / c)) points = [] for i in range(n): for j in range(i+1, n): points += calc_intersection_points(circles[i], circles[j]) for x, y, _ in niku: points.append((x, y)) cooked = 0 for x, y in points: ret = 0 for cx, cy, cr in circles: if math.hypot(x - cx, y - cy) <= cr + eps: ret += 1 if ret > cooked: cooked = ret if cooked >= k: r = mid else: l = mid print(l) ```
instruction
0
21,797
9
43,594
Yes
output
1
21,797
9
43,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` import sys input = sys.stdin.readline from math import sqrt N,K=map(int,input().split()) M=[tuple(map(int,input().split())) for i in range(N)] def cross_coor(x0,y0,c0,x1,y1,c1): # 二円の交点 if (c1-c0)**2<=(x1-x0)**2+(y1-y0)**2<=(c0+c1)**2: x2,y2=x1-x0,y1-y0 a=(x2**2+y2**2+c0**2-c1**2)/2 xa=(a*x2+y2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+x0 ya=(a*y2-x2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+y0 xb=(a*x2-y2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+x0 yb=(a*y2+x2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+y0 return [(xa,ya),(xb,yb)] else: return False OK=1<<31 NG=0 while OK-NG>10**(-8): mid=(OK+NG)/2 CANDI=[] for i in range(N): x0,y0,c0=M[i] CANDI.append((x0,y0)) for j in range(i+1,N): x1,y1,c1=M[j] CR=cross_coor(x0,y0,mid/c0,x1,y1,mid/c1) if CR: CANDI.extend(CR) for z,w in CANDI: count=0 for x,y,c in M: if (c**2)*((x-z)**2+(y-w)**2)<=(mid+10**(-8))**2: count+=1 if count>=K: OK=mid break else: NG=mid print((OK+NG)/2) ```
instruction
0
21,798
9
43,596
Yes
output
1
21,798
9
43,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): # 2円の中心間の距離の2乗 def D2(x1,y1,x2,y2): return (x1-x2)**2+(y1-y2)**2 # 2円が交点を持つか def check(R1,R2): x1,y1,r1 = R1 x2,y2,r2 = R2 d2 = D2(x1,y1,x2,y2) if (r1-r2)**2 < d2 <= (r1+r2)**2: return 1 else: return 0 # 2円の交点を出力 def point(R1,R2): if not check(R1,R2): return [] else: x1,y1,r1 = R1 x2,y2,r2 = R2 x2 -= x1 y2 -= y1 r = x2**2+y2**2 a = (r+r1**2-r2**2)/2 d = (r*r1**2-a**2)**0.5 X,Y = a*x2/r, a*y2/r k = d/r X1,Y1 = X+y2*k+x1, Y-x2*k+y1 X2,Y2 = X-y2*k+x1, Y+x2*k+y1 return [(X1,Y1),(X2,Y2)] # 円に点が入っているか def inR(p,R): x2,y2 = p x1,y1,r1 = R d2 = D2(x1,y1,x2,y2) if d2 <= r1**2+1e-3: return 1 else: return 0 n,k = LI() p = LIR(n) l = 0 r = 1000000 while r-l > 1e-6: t = (l+r) / 2 P = [] for i in range(n): xi,yi,ci = p[i] ri = t/ci P.append((xi,yi)) for j in range(i): xj,yj,cj = p[j] rj = t/cj ps = point((xi,yi,ri),(xj,yj,rj)) for pi in ps: P.append(pi) for pi in P: s = 0 for x,y,c in p: r1 = t/c if inR(pi,(x,y,r1)): s += 1 if s >= k: break if s >= k: r = t break else: l = t print(l) return #Solve if __name__ == "__main__": solve() ```
instruction
0
21,799
9
43,598
Yes
output
1
21,799
9
43,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` import numpy as np from scipy.optimize import basinhopping, minimize import sys input = sys.stdin.buffer.readline def main() -> None: N, K = map(int, input().split()) A = np.array(list(map(int, sys.stdin.read().split()))) X, Y, C = A[::3], A[1::3], A[2::3] def f(x, X=X, Y=Y, C=C): return np.sort(C * np.sqrt(np.power(X-x[0], 2) + np.power(Y-x[1], 2)))[K-1] # res = minimize(f, [0, 0], method='Nelder-Mead', tol=1e-7) res = basinhopping(f, [0, 0], niter=100) print("{:.10f}".format(f(res.x))) if __name__ == '__main__': main() ```
instruction
0
21,800
9
43,600
No
output
1
21,800
9
43,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` N,K = map(int,input().split()) niku = [tuple(map(int,input().split())) for _ in range(N)] ans = 10**18 for i in range(N-1): x1,y1,c1 = niku[i] for j in range(i+1,N): x2,y2,c2 = niku[j] X = c1*x1/(c1+c2)+c2*x2/(c1+c2) Y = c1*y1/(c1+c2)+c2*y2/(c1+c2) time = [] for k in range(N): xk,yk,ck = niku[k] time.append(ck*((X-xk)**2+(Y-yk)**2)**0.5) time.sort() ans = min(ans,time[K-1]) for i in range(N): X,Y,_ = niku[i] time = [] for k in range(N): xk,yk,ck = niku[k] time.append(ck*((X-xk)**2+(Y-yk)**2)**0.5) time.sort() ans = min(ans,time[K-1]) for i in range(N-1): x1,y1,c1 = niku[i] for j in range(i+1,N): x2,y2,c2 = niku[j] if c1 == c2: continue X = c1*x1/(c1-c2)-c2*x2/(c1-c2) Y = c1*y1/(c1-c2)-c2*y2/(c1-c2) time = [] for k in range(N): xk,yk,ck = niku[k] time.append(ck*((X-xk)**2+(Y-yk)**2)**0.5) time.sort() ans = min(ans,time[K-1]) for i in range(N-2): x1,y1,c1 = niku[i] for j in range(i+1,N-1): x2,y2,c2 = niku[j] for k in range(j+1,N): x3,y3,c3 = niku[k] X = c1*x1/(c1+c2+c3)+c2*x2/(c1+c2+c3)+c3*x3/(c1+c2+c3) Y = c1*y1/(c1+c2+c3)+c2*y2/(c1+c2+c3)+c3*y3/(c1+c2+c3) time = [] for l in range(N): xk,yk,ck = niku[l] time.append(ck*((X-xk)**2+(Y-yk)**2)**0.5) time.sort() ans = min(ans,time[K-1]) print(ans) ```
instruction
0
21,801
9
43,602
No
output
1
21,801
9
43,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` import sys sys.setrecursionlimit(10**9) N, K = map(int,input().split()) niku = list(list(map(int,input().split()))for _ in range(N)) ans = float('inf') def func(l,r): if r-l <= 10**(-8) or r-l < r*(10**(-8)): return l mid = (l+r)/2 hoge = [[0]*N for _ in range(N)] count = N for i in range(N): hoge[i][i] = 1 for j in range(i+1,N): if ((niku[i][1]-niku[j][1])**2 + (niku[i][0]-niku[j][0])**2) <= (mid/niku[i][2] + mid/niku[j][2])**2: hoge[i][j] = 1 hoge[j][i] = 1 while 1: dex = 0 num = 0 zero = 0 for i in range(N): fuga = N-sum(hoge[i]) if fuga > num: num = fuga dex = i zero += fuga if zero == 0: break for i in range(N): if hoge[i][dex] == 0: hoge[i][dex] = 1 hoge[dex][i] = 1 zero -= 2 count -= 1 if count >= K: return func(l,mid) else: return func(mid,r) print(func(0,10**9)) ```
instruction
0
21,802
9
43,604
No
output
1
21,802
9
43,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \left(x_i, y_i\right), and its hardness is c_i. Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \left(X, Y\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2} seconds. Takahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time. Constraints * All values in input are integers. * 1 \leq N \leq 60 * 1 \leq K \leq N * -1000 \leq x_i , y_i \leq 1000 * \left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right) * 1 \leq c_i \leq 100 Input Input is given from Standard Input in the following format: N K x_1 y_1 c_1 \vdots x_N y_N c_N Output Print the answer. It will be considered correct if its absolute or relative error from our answer is at most 10^{-6}. Examples Input 4 3 -1 0 3 0 0 3 1 0 2 1 1 40 Output 2.4 Input 10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 Output 7411.2252 Submitted Solution: ``` def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] import math [n,k]=i2() d=[] for i in range(n): d.append(i2()) def check(t): for x1,y1,c1 in d: for x2,y2,c2 in d: if x1==x2 and y1==y2: continue aa=2*(x1-x2) bb=2*(y1-y2) cc=t**2*(1/c2**2-1/c1**2)+x1**2-x2**2+y1**2-y2**2 if aa==0: continue ss=bb**2/aa**2+1 tt=bb/aa*(x1-cc/aa)-y1 uu=(x1-cc/aa)**2+y1**2-(t/c1)**2 if tt**2-ss*uu<0 or ss==0: continue Y1=-tt-math.sqrt(tt**2-ss*uu) Y1/=ss X1=(cc-bb*Y1)/aa count=0 for x,y,c in d: if c*math.sqrt((X1-x)**2+(Y1-y)**2)<=t: count+=1 if count>=k: return True Y2=-tt+math.sqrt(tt**2-ss*uu) Y2/=ss X2=(cc-bb*Y2)/aa count=0 for x,y,c in d: if c*math.sqrt((X2-x)**2+(Y2-y)**2)<=t: count+=1 if count>=k: return True for X,Y,C in d: count=0 for x,y,c in d: if c*math.sqrt((X-x)**2+(Y-y)**2)<=t: count+=1 if count>=k: return True return False low=0 high=100*3000 eps=10**(-7) while high-low>eps: mid=(low+high)/2 if check(mid): high=mid else: low=mid print(high) ```
instruction
0
21,803
9
43,606
No
output
1
21,803
9
43,607
Provide a correct Python 3 solution for this coding contest problem. E869120's and square1001's 16-th birthday is coming soon. Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces. E869120 and square1001 were just about to eat A and B of those pieces, respectively, when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake". Can both of them obey the instruction in the note and take desired numbers of pieces of cake? Constraints * A and B are integers between 1 and 16 (inclusive). * A+B is at most 16. Input Input is given from Standard Input in the following format: A B Output If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`. Examples Input 5 4 Output Yay! Input 8 8 Output Yay! Input 11 4 Output :(
instruction
0
21,852
9
43,704
"Correct Solution: ``` a,b=map(int,input().split()) print('Yay!' if (a<9 and b<9) else ':(') ```
output
1
21,852
9
43,705