message stringlengths 2 20.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 1.95k 109k | cluster float64 17 17 | __index_level_0__ int64 3.91k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [0] * n
s = sorted(enumerate(a), key=lambda x: x[1], reverse=True)
# print(s)
p = 1
first = 0
last = n - 1
spaces = []
sn = 150
# print(s)
for i in s:
j = i[0]
if b[j] > 0:
continue
# print(i[1])
jk = k + 1
g = 0
while j >= first and jk > 0:
if b[j] == 0:
b[j] = p
jk -= 1
else:
g += 1
if g > sn:
for sp in spaces[::-1]:
if sp[0] < j < sp[1]:
j = sp[0]
break
# print(j, end=" ")
j -= 1
if jk > 0:
first = i[0] + k
jf = j
j = i[0]
jk = k
g = 0
while j <= last and jk > 0:
if b[j] == 0:
b[j] = p
jk -= 1
else:
g += 1
if g > sn:
for sp in spaces[::-1]:
if sp[0] < j < sp[1]:
j = sp[1]
break
# print(j, end=" ")
j += 1
if jk > 0:
last = i[0] - k
jl = j
if jl - jf > sn * 3:
spaces.append((jf + 1, jl - 1))
# print(i)
# print(*b, sep="")
# print(spaces)
# print()
p = 1 if p == 2 else 2
# print(*b)
print(*b, sep="")
# print(spaces)
# print(len(spaces))
print(len(spaces))
``` | instruction | 0 | 96,170 | 17 | 192,340 |
No | output | 1 | 96,170 | 17 | 192,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
pos = sorted([(l[i], i) for i in range(n)], reverse = True)
t = 1
for x in pos:
p = x[1]
if l[p] < 0:
continue
while p >= 0 and l[p] > 0 and x[1] - p <= k:
l[p] = -t
p -= 1
p = x[1] + 1
while p < n and l[p] > 0 and p - x[1] <= k:
l[p] = -t
p += 1
t += 1 if t == 1 else -1
print(''.join(str(-i) for i in l))
``` | instruction | 0 | 96,171 | 17 | 192,342 |
No | output | 1 | 96,171 | 17 | 192,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students standing in a row. Two coaches are forming two teams β the first coach chooses the first team and the second coach chooses the second team.
The i-th student has integer programming skill a_i. All programming skills are distinct and between 1 and n, inclusive.
Firstly, the first coach will choose the student with maximum programming skill among all students not taken into any team, and k closest students to the left of him and k closest students to the right of him (if there are less than k students to the left or to the right, all of them will be chosen). All students that are chosen leave the row and join the first team. Secondly, the second coach will make the same move (but all students chosen by him join the second team). Then again the first coach will make such move, and so on. This repeats until the row becomes empty (i. e. the process ends when each student becomes to some team).
Your problem is to determine which students will be taken into the first team and which students will be taken into the second team.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of students and the value determining the range of chosen students during each move, respectively.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ n), where a_i is the programming skill of the i-th student. It is guaranteed that all programming skills are distinct.
Output
Print a string of n characters; i-th character should be 1 if i-th student joins the first team, or 2 otherwise.
Examples
Input
5 2
2 4 5 3 1
Output
11111
Input
5 1
2 1 3 5 4
Output
22111
Input
7 1
7 2 1 3 5 4 6
Output
1121122
Input
5 1
2 4 5 3 1
Output
21112
Note
In the first example the first coach chooses the student on a position 3, and the row becomes empty (all students join the first team).
In the second example the first coach chooses the student on position 4, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
In the third example the first coach chooses the student on position 1, and the row becomes [1, 3, 5, 4, 6] (students with programming skills [2, 7] join the first team). Then the second coach chooses the student on position 5, and the row becomes [1, 3, 5] (students with programming skills [4, 6] join the second team). Then the first coach chooses the student on position 3, and the row becomes [1] (students with programming skills [3, 5] join the first team). And then the second coach chooses the remaining student (and the student with programming skill 1 joins the second team).
In the fourth example the first coach chooses the student on position 3, and the row becomes [2, 1] (students with programming skills [3, 4, 5] join the first team). Then the second coach chooses the student on position 1, and the row becomes empty (and students with programming skills [1, 2] join the second team).
Submitted Solution:
```
n, k = map(int, input().split())
numbers = list(map(int, input().split()))
myValues = {}
teams = [0 for i in range(len(numbers))]
import sys
sys.setrecursionlimit(3500)
class Value:
def __init__(self, skill, index, previousVal = None, nextVal = None):
self.skill = skill
self.index = index
self.previousVal = previousVal
self.nextVal = nextVal
def __gt__(self, other):
return self.skill > other.skill
def __repr__(self):
return str(self)
def __str__(self):
return "(skill: "+str(self.skill)+",index: "+str(self.index)+")"
def addPrevious(value, team, k):
myValues.pop(value.index)
teams[value.index] = team
if value.nextVal:
value.nextVal.previousVal = value.previousVal
if value.previousVal:
value.previousVal.nextVal = value.nextVal
if k>0 and value.previousVal:
addPrevious(value.previousVal, team, k-1)
def addNext(value, team, k):
myValues.pop(value.index)
teams[value.index] = team
if value.nextVal:
value.nextVal.previousVal = value.previousVal
if value.previousVal:
value.previousVal.nextVal = value.nextVal
if k>0 and value.nextVal:
addNext(value.nextVal, team, k-1)
def addToTeam(value, team, k):
myValues.pop(value.index)
teams[value.index] = team
if value.nextVal:
value.nextVal.previousVal = value.previousVal
if value.previousVal:
value.previousVal.nextVal = value.nextVal
if k>0:
if value.nextVal:
addNext(value.nextVal, team, k-1)
if value.previousVal:
addPrevious(value.previousVal, team, k-1)
def getValue(someObject):
return someObject[1].skill
try:
currValue = Value(numbers[0], 0)
myValues[0] = currValue
for i in range(1,len(numbers)):
newValue = Value(numbers[i], i, currValue)
myValues[i] = newValue
currValue = newValue
while True:
if currValue.previousVal:
currValue.previousVal.nextVal = currValue
currValue = currValue.previousVal
else:
break
currTeam = 1
sortedList = sorted(myValues.items(), key = getValue, reverse = True)
for i in sortedList:
if i[0] in myValues:
currTeam = (currTeam+1)%2
addToTeam(i[1], currTeam+1, k)
teamString = ""
for i in teams:
teamString += str(i)
print(teamString)
except Exception as e:
print(str(e))
``` | instruction | 0 | 96,172 | 17 | 192,344 |
No | output | 1 | 96,172 | 17 | 192,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.
Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points.
Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort.
After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n + 1 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here.
Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible.
Input
The first line contains a pair of integers n and k (1 β€ k β€ n + 1). The i-th of the following n lines contains two integers separated by a single space β pi and ei (0 β€ pi, ei β€ 200000).
The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
* In subproblem C1 (4 points), the constraint 1 β€ n β€ 15 will hold.
* In subproblem C2 (4 points), the constraint 1 β€ n β€ 100 will hold.
* In subproblem C3 (8 points), the constraint 1 β€ n β€ 200000 will hold.
Output
Print a single number in a single line β the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1.
Examples
Input
3 2
1 1
1 4
2 2
Output
3
Input
2 1
3 2
4 0
Output
-1
Input
5 2
2 10
2 10
1 1
3 1
3 1
Output
12
Note
Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place.
Consider the second test case. Even if Manao wins against both opponents, he will still rank third. | instruction | 0 | 97,326 | 17 | 194,652 |
Tags: brute force
Correct Solution:
```
m = 301000
ns = [0] * m
es = [0] * m
c = [0] * m
b = [0] * m
t = [0] * m
P = 0
def add(b, k):
k = t[k]
while k:
e = es[k]
if b[-1] > e: b[-1] = e
b[e] += 1
k = ns[k]
def delete(b):
for i in range(b[m - 1], m + 1):
if b[i]:
b[i] -= 1
b[-1] = i
return i
def calc(k):
global b
q = 0
b = [0] * m
b[-1] = m
take = rank - dn
if take < 0: take = 0
add(b, k)
add(b, k - 1)
for i in range(1, take + 1): q += delete(b)
for i in range(k - 1): add(b, i)
for i in range(k + 1, P + 1): add(b, i)
for i in range(1, k - take + 1): q += delete(b)
return q
n, k = map(int, input().split())
rank = n - k + 1
if rank == 0:
print('0')
exit(0)
for i in range(1, n + 1):
p, e = map(int, input().split())
if p > P: P = p
c[p] += 1
es[i], ns[i] = e, t[p]
t[p] = i
dn = 0
for i in range(1, n + 1):
if i > 1: dn += c[i - 2]
if c[i] + c[i - 1] + dn >= rank and rank <= i + dn:
u = calc(i)
if i < n:
dn += c[i - 1]
v = calc(i + 1)
if u > v: u = v
if i < n - 1:
dn += c[i]
v = calc(i + 2)
if u > v: u = v
print(u)
exit(0)
print('-1')
``` | output | 1 | 97,326 | 17 | 194,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.
If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum ai in the group minus the minimum ai in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k?
Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.
Input
The first line contains two space-separated integers n and k (1 β€ n β€ 200, 0 β€ k β€ 1000) β the number of students and the maximum total imbalance allowed, respectively.
The second line contains n space-separated integers ai (1 β€ ai β€ 500) β the time it takes the i-th student to complete his/her independent piece of work.
Output
Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7.
Examples
Input
3 2
2 4 5
Output
3
Input
4 3
7 8 9 10
Output
13
Input
4 0
5 10 20 21
Output
1
Note
In the first sample, we have three options:
* The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2.
* The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1.
* All three students form their own groups. Total imbalance is 0.
In the third sample, the total imbalance must be 0, so each student must work individually.
Submitted Solution:
```
# You lost the game.
def binom(n, k):
res = 1
# Since C(n, k) = C(n, n-k)
if ( k > n - k ):
k = n - k
# Calculate value of [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for i in range(k):
res *= (n - i)
res /= (i + 1)
return res;
n, k = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
B = [1,1,2,5,15,52,203,877]
for k in range(8,n):
r = 0
for i in range(1,k):
r += binom(k,i)*B[i]
B[k] = r
T = [0 for _ in range(n)]
f = 0
d = 0
while d < n:
if f == n or L[f]-L[d] > k:
T[d] = f
d += 1
else:
f += 1
R = []
r = B[T[0]]
for i in range(1,d):
if i > T[i-1]:
R += [r]
r = B[T[i]-i]
else:
r += B[T[i]-i]-B[T[i-1]-i]
print(max(R+[r]))
``` | instruction | 0 | 98,260 | 17 | 196,520 |
No | output | 1 | 98,260 | 17 | 196,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.
If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum ai in the group minus the minimum ai in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k?
Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.
Input
The first line contains two space-separated integers n and k (1 β€ n β€ 200, 0 β€ k β€ 1000) β the number of students and the maximum total imbalance allowed, respectively.
The second line contains n space-separated integers ai (1 β€ ai β€ 500) β the time it takes the i-th student to complete his/her independent piece of work.
Output
Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7.
Examples
Input
3 2
2 4 5
Output
3
Input
4 3
7 8 9 10
Output
13
Input
4 0
5 10 20 21
Output
1
Note
In the first sample, we have three options:
* The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2.
* The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1.
* All three students form their own groups. Total imbalance is 0.
In the third sample, the total imbalance must be 0, so each student must work individually.
Submitted Solution:
```
q,w=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=0
import math
for i in range(0,q-1):
j=i
while (j<q):
if (a[j]-a[i])<=w:
j+=1
else:
break
m=j-i-1
n=math.factorial(m)
for j in range(1,m+1):
r+=n//(math.factorial(j)*math.factorial(m-j))
print(r+1)
``` | instruction | 0 | 98,261 | 17 | 196,522 |
No | output | 1 | 98,261 | 17 | 196,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.
If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum ai in the group minus the minimum ai in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k?
Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.
Input
The first line contains two space-separated integers n and k (1 β€ n β€ 200, 0 β€ k β€ 1000) β the number of students and the maximum total imbalance allowed, respectively.
The second line contains n space-separated integers ai (1 β€ ai β€ 500) β the time it takes the i-th student to complete his/her independent piece of work.
Output
Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7.
Examples
Input
3 2
2 4 5
Output
3
Input
4 3
7 8 9 10
Output
13
Input
4 0
5 10 20 21
Output
1
Note
In the first sample, we have three options:
* The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2.
* The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1.
* All three students form their own groups. Total imbalance is 0.
In the third sample, the total imbalance must be 0, so each student must work individually.
Submitted Solution:
```
import math
modulo = math.pow(10, 9) + 7
def findways(arr, curr, k, dp):
if(curr >= len(arr) - 1):
return 0
if(dp[curr][k] != -1):
return dp[curr][k]
c = 0
for i in range(curr + 1, len(arr)):
if(arr[i] - arr[curr] <= k):
c = c + 1
dp[i][k - (arr[i] - arr[curr])] = findways(arr, i, k - (arr[i] - arr[curr]), dp)
c = c + dp[i][k - (arr[i] - arr[curr])]
else:
break
dp[curr + 1][k] = z = findways(arr, curr + 1, k, dp)
dp[curr][k] = (c + z) % modulo
return int((c + z) % modulo)
n, k = list(map(int, input().split(" ")))
arr = list(map(int, input().split(" ")))
arr.sort()
dp = [[-1 for i in range(k + 1)] for j in range(n + 1)]
s = findways(arr, 0, k, dp)
print(s + 1)
``` | instruction | 0 | 98,262 | 17 | 196,524 |
No | output | 1 | 98,262 | 17 | 196,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,279 | 17 | 196,558 |
Tags: greedy, implementation
Correct Solution:
```
n,m = map(int,input().split())
l = []
for i in range(m):
la,r,t,c = map(int,input().split())
l.append([la,r,t,c])
cost = 0
for i in range(n):
min_time = 10**12
for j in range(m):
if l[j][0]<=i+1<=l[j][1]:
if l[j][2]<min_time:
min_time = l[j][2]
ans = j
if min_time!=10**12:
cost+=l[ans][3]
print(cost)
``` | output | 1 | 98,279 | 17 | 196,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,280 | 17 | 196,560 |
Tags: greedy, implementation
Correct Solution:
```
#N sections each with m participants
#[li,ri] sections for ith participant
n,m=map(int,input().split())
play=[]
for i in range(m):
l,r,t,c=map(int,input().split())
play.append([l,r,t,c])
sm=0
for i in range(1,n+1):
mini=10**9
get=0
for j in range(m):
l,r,t,c=play[j][0],play[j][1],play[j][2],play[j][3]
if l<=i<=r :
if t<mini:
mini=t
get=c
sm+=get
print(sm)
``` | output | 1 | 98,280 | 17 | 196,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,281 | 17 | 196,562 |
Tags: greedy, implementation
Correct Solution:
```
n,m=map(int,input().split(" "));
a=[]
for i in range(m):
k=list(map(int,input().split(" ")))
a.append(k)
total=0;
for i in range(1,n+1):
temp=0
ans=0;
for j in a:
if i>=j[0] and i<=j[1]:
if ans==0:
ans=j[2];
temp=j[3]
elif j[2]<ans:
ans=j[2]
temp=j[3]
total=total+temp
print(total)
``` | output | 1 | 98,281 | 17 | 196,563 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,282 | 17 | 196,564 |
Tags: greedy, implementation
Correct Solution:
```
import sys
inp = sys.stdin.readlines()
all_lines = []
for line in inp:
all_lines.append(list(map(int, line.split(' '))))
num_athletes = all_lines[0][1]
num_sections = all_lines[0][0]
profit = 0
for section in range(num_sections):
least_time = 0
i = 0
earning = 0
for athlete in all_lines[1:]:
if athlete[0]-1 <= section and athlete[1]-1 >= section:
if i == 0:
least_time =athlete[2]
earning = athlete[3]
elif athlete[2]<least_time:
least_time = athlete[2]
earning = athlete[3]
i += 1
profit += earning
print(profit)
``` | output | 1 | 98,282 | 17 | 196,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,283 | 17 | 196,566 |
Tags: greedy, implementation
Correct Solution:
```
n,m=map(int,input().split())
vis=[0]*(n+1)
ans=0
arr=[]
for i in range(m):
arr.append(list(map(int,input().split())))
arr.sort(key=lambda i:i[2])
for i in range(m):
for j in range(arr[i][0],arr[i][1]+1):
if not vis[j]:
vis[j]=1
ans+=arr[i][3]
print(ans)
``` | output | 1 | 98,283 | 17 | 196,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,284 | 17 | 196,568 |
Tags: greedy, implementation
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(m)]
ans = 0
for i in range(1, n + 1):
time, profit = 10**9, 0
for j in range(m):
if a[j][0] <= i <= a[j][1] and time > a[j][2]:
time = a[j][2]
profit = a[j][3]
ans += profit
print(ans)
``` | output | 1 | 98,284 | 17 | 196,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,285 | 17 | 196,570 |
Tags: greedy, implementation
Correct Solution:
```
sections, n_p = [int(x) for x in input().split(' ')]
participants = []
paritipants_on_sections = [(0, 1000000000000000000)] * (sections + 1) # profit + time
for i in range(n_p):
# participants.append([int(x) for x in input().split(' ')])
start, end, time, profit = [int(x) for x in input().split(' ')]
# print('---')
for j in range(start, end+1):
tmp_time = j * time
# print(tmp_time)
if tmp_time < paritipants_on_sections[j][1]:
paritipants_on_sections[j] = (profit, tmp_time)
print(sum(x[0] for x in paritipants_on_sections))
``` | output | 1 | 98,285 | 17 | 196,571 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles. | instruction | 0 | 98,286 | 17 | 196,572 |
Tags: greedy, implementation
Correct Solution:
```
m, n = map(int, input().split())
p = [(1001, 0, 0)] * m
for i in range(n):
l, r, t, c = map(int, input().split())
p[l - 1: r] = [min((x, y, z), (t, i, - c)) for x, y, z in p[l - 1: r]]
print(- sum(z for x, y, z in p))
``` | output | 1 | 98,286 | 17 | 196,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
n = [int(i) for i in input().split()]
batata = [1001]*(n[0])
score = [0]*(n[0])
for i in range(n[1]):
all = [int(i) for i in input().split()]
for b in range(all[0]-1, all[1]):
if batata[b] > all[2]:
batata[b] = all[2]
score[b] = all[3]
sum = 0
for i in range(n[0]):
sum += score[i]
print(sum)
``` | instruction | 0 | 98,287 | 17 | 196,574 |
Yes | output | 1 | 98,287 | 17 | 196,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
from sys import stdin,stdout
import math
from collections import Counter,deque
L=lambda:list(map(int, stdin.readline().strip().split()))
M=lambda:map(int, stdin.readline().strip().split())
I=lambda:int(stdin.readline().strip())
IN=lambda:stdin.readline().strip()
C=lambda:stdin.readline().strip().split()
mod=1000000007
#Keymax = max(Tv, key=Tv.get)
def s(a):print(" ".join(list(map(str,a))))
#______________________-------------------------------_____________________#
#I_am_pavan
def solve():
n,m=M()
a=[[] for i in range(n+1)]
for i in range(m):
l,r,t,c=M()
for j in range(l,r+1):
a[j].append((t,c))
count=0
for i in range(1,n+1):
x=len(a[i])
if x==0:
continue
t=1001
for j in range(x):
if t>a[i][j][0]:
ans=a[i][j][1]
t=a[i][j][0]
count+=ans
print(count)
t=1
for i in range(t):
solve()
``` | instruction | 0 | 98,288 | 17 | 196,576 |
Yes | output | 1 | 98,288 | 17 | 196,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
n,m=map(int,input().split())
racer=[-1]*(n+1);profit=[0]*(n+1);
for i in range(m):
l,r,c,p=map(int,input().split())
for i in range(l,r+1):
if(racer[i]==-1 or racer[i]>c):profit[i]=p;racer[i]=c;
print(sum(profit))
``` | instruction | 0 | 98,289 | 17 | 196,578 |
Yes | output | 1 | 98,289 | 17 | 196,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
def solve(sections):
profit = 0
for i in sections:
if not i:
continue
min = (i[0][0], i[0][1])
for j in i:
if j[0] < min[0]:
min = j
profit += min[1]
return profit
n, m = [int(i) for i in input().split()]
sections = [[] for i in range(n)]
for i in range(m):
l, r, t, c = [int(j) for j in input().split()]
for j in range(l-1, r):
sections[j] += [(t, c)]
print(solve(sections))
``` | instruction | 0 | 98,290 | 17 | 196,580 |
Yes | output | 1 | 98,290 | 17 | 196,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
n = [int(i) for i in input().split()]
batata = [1000]*(n[0])
score = [0]*(n[0])
for i in range(n[1]):
all = [int(i) for i in input().split()]
for b in range(all[0]-1, all[1]):
if batata[b] > all[2]:
batata[b] = all[2]
score[b] = all[3]
sum = 0
for i in range(n[0]):
sum += score[i]
print(sum)
``` | instruction | 0 | 98,291 | 17 | 196,582 |
No | output | 1 | 98,291 | 17 | 196,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
n,m=map(int,input().split())
list1=[111]*(n+1)
list2=[0]*(n+1)
for i in range(m):
l,r,t,c=map(int,input().split())
x=r-l+1
for j in range(l,r+1):
if(list1[j]>t):
list1[j]=t
list2[j]=c
elif(list1[j]==t and list2[j]<c):
list2[j]=c
print(sum(list2))
``` | instruction | 0 | 98,292 | 17 | 196,584 |
No | output | 1 | 98,292 | 17 | 196,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
n, m = map(int, input().split())
tab = []
for _ in range(m):
l = list(map(int, input().split()))
tab.append(l)
tab = list(map(list, tab))
p = 0
for i in range(1, n+1):
s = 0
t = 1000
a = ''
for j in range(m):
if i in range(tab[j][0], tab[j][1]+1):
if tab[j][2] < t:
s = tab[j][3]
t = tab[j][2]
a = j
p += s
print(p)
``` | instruction | 0 | 98,293 | 17 | 196,586 |
No | output | 1 | 98,293 | 17 | 196,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.
To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known:
* li β the number of the starting section,
* ri β the number of the finishing section (li β€ ri),
* ti β the time a biathlete needs to complete an section of the path,
* ci β the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman.
The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)Β·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives kΒ·ci roubles.
In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.
We should also add that Nikita can bet on each section and on any contestant running in this section.
Help the friends find the maximum possible profit.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 β€ li β€ ri β€ n, 1 β€ ti, ci β€ 1000).
Output
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
Examples
Input
4 4
1 4 20 5
1 3 21 10
3 3 4 30
3 4 4 20
Output
60
Input
8 4
1 5 24 10
2 4 6 15
4 6 30 50
6 7 4 20
Output
105
Note
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.
Submitted Solution:
```
m, n = map(int, input().split())
p = [(-1000, 0)] * m
for i in range(n):
l, r, t, c = map(int, input().split())
p[l - 1: r] = [max((i, j), (-t, c)) for i, j in p[l - 1: r]]
print(sum(j for i, j in p))
``` | instruction | 0 | 98,294 | 17 | 196,588 |
No | output | 1 | 98,294 | 17 | 196,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,899 | 17 | 197,798 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
n, s = map(int, input().split())
a = sorted(map(int, input().split()), reverse = True)
b = sorted(map(int, input().split()))
i = j = 0
while i < n and j < n:
if a[i] + b[j] < s: j += 1
else:
i += 1
j += 1
print(1, i)
``` | output | 1 | 98,899 | 17 | 197,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,900 | 17 | 197,800 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
from bisect import bisect_left, bisect_right
class Result:
def __init__(self, index, value):
self.index = index
self.value = value
class BinarySearch:
def __init__(self):
pass
@staticmethod
def greater_than(num: int, func, size: int = 1):
"""Searches for smallest element greater than num!"""
if isinstance(func, list):
index = bisect_right(func, num)
if index == len(func):
return Result(None, None)
else:
return Result(index, func[index])
else:
alpha, omega = 0, size - 1
if func(omega) <= num:
return Result(None, None)
while alpha < omega:
if func(alpha) > num:
return Result(alpha, func(alpha))
if omega == alpha + 1:
return Result(omega, func(omega))
mid = (alpha + omega) // 2
if func(mid) > num:
omega = mid
else:
alpha = mid
@staticmethod
def less_than(num: int, func, size: int = 1):
"""Searches for largest element less than num!"""
if isinstance(func, list):
index = bisect_left(func, num) - 1
if index == -1:
return Result(None, None)
else:
return Result(index, func[index])
else:
alpha, omega = 0, size - 1
if func(alpha) >= num:
return Result(None, None)
while alpha < omega:
if func(omega) < num:
return Result(omega, func(omega))
if omega == alpha + 1:
return Result(alpha, func(alpha))
mid = (alpha + omega) // 2
if func(mid) < num:
alpha = mid
else:
omega = mid
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b, reverse=True)
ans = 0
bs = BinarySearch()
c = []
for i in range(n):
val = b[i]
req = x - val - 1
ind = bs.greater_than(req, a).index
if ind is None:break
ind = n - ind
#print(req, ind)
c += [ind]
c = sorted(c)
for i in range(len(c)):
if c[i] > ans:
ans += 1
print(1, ans)
``` | output | 1 | 98,900 | 17 | 197,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,901 | 17 | 197,802 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
from sys import stdin,stdout
import bisect as bs
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr()):
n,sm=lst()
a=sorted(lst(),reverse=1)
b=sorted(lst())
used=-1
rank=1
# print(a)
# print(b)
p=-1
for i in range(n):
v1=a[i]
p=bs.bisect_left(b,sm-v1,p+1,n)
# print(a[i],p)
if p>=n:
rank=i
# print(rank)
break
rank=i+1
print(1,rank)
``` | output | 1 | 98,901 | 17 | 197,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,902 | 17 | 197,804 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
n,x = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()), reverse = True)
pa,pb = 0,0
worst = 0
while pa < len(a) and pb < len(b) :
if a[pa] + b[pb] >= x :
worst += 1
pb += 1
pa += 1
print(1, worst)
``` | output | 1 | 98,902 | 17 | 197,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,903 | 17 | 197,806 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#n=int(input())
#arr = list(map(int, input().split()))
n,x= map(int, input().split())
arr = sorted(list(map(int, input().split())))
ls = list(map(int, input().split()))
ls=sorted(ls,reverse=True)
#print(arr)
#print(ls)
ans=0
j=0
for i in range(n):
while j<n and arr[j]+ls[i]<x:
j+=1
if j<n and arr[j]+ls[i]>=x:
ans+=1
j+=1
print(1, ans)
``` | output | 1 | 98,903 | 17 | 197,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,904 | 17 | 197,808 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
n, x = map(int, input().split())
score1 = map(int, input().split())
score2 = map(int, input().split())
score1 = sorted(score1, reverse=True)
score2 = sorted(score2, reverse=True)
count = 0
i = k = 0
j = l = (n - 1)
while i <= j and k <= l:
if score1[i] + score2[l] >= score2[k] + score1[j]:
if score1[i] + score2[l] >= x:
count += 1
i += 1
l -= 1
else:
if score2[k] + score1[j] >= x:
count += 1
k += 1
j -= 1
print(1, count)
``` | output | 1 | 98,904 | 17 | 197,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,905 | 17 | 197,810 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
from operator import add
from bisect import bisect_left
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
b_len = len(b)
ans = 0
for i in range(n):
pos = bisect_left(b, x - a[i])
if not pos > b_len - 1:
#del b[pos]
b_len -= 1
ans += 1
print(1, ans)
``` | output | 1 | 98,905 | 17 | 197,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly. | instruction | 0 | 98,906 | 17 | 197,812 |
Tags: binary search, greedy, sortings, two pointers
Correct Solution:
```
from sys import stdin
from collections import deque
n,x = [int(x) for x in stdin.readline().split()]
s1 = deque(sorted([int(x) for x in stdin.readline().split()]))
s2 = deque(sorted([int(x) for x in stdin.readline().split()]))
place = 0
for score in s1:
if s2[-1] + score >= x:
place += 1
s2.pop()
else:
s2.popleft()
print(1,place)
``` | output | 1 | 98,906 | 17 | 197,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz/'
M=998244353
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
n,k=value()
a=sorted(array(),reverse=True)
b=sorted(array())
Ii=0
Ij=n-1
have=have=a[Ii]+b[Ij]
for i in range(n):
j=bisect_left(b,k-a[i])
if(j<n and k<=a[i]+b[j]<have):
Ii=i
Ij=j
have=a[i]+b[j]
a.remove(a[Ii])
b.remove(b[Ij])
n-=1
# print(have)
# print(a)
# print(b)
ans1=1
ans2=1
low=0
for i in a:
need=have-i
j=max(low,bisect_left(b,need))
if(j<n and b[j]+i>=have):
ans2+=1
low=j+1
print(ans1,ans2)
``` | instruction | 0 | 98,907 | 17 | 197,814 |
Yes | output | 1 | 98,907 | 17 | 197,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
Submitted Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b, reverse=True)
ans = 0
for i in range(n):
if (a[i]+b[i]) >= x:
ans += 1
print(1, ans)
``` | instruction | 0 | 98,908 | 17 | 197,816 |
No | output | 1 | 98,908 | 17 | 197,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
Submitted Solution:
```
from bisect import bisect_left, bisect_right
s, n = map(int, input().split())
p = list(map(int, input().split()))
for i, j in enumerate(map(int, input().split())): p[i] += j
p.sort()
a, b = bisect_left(p, n), bisect_right(p, n)
print(1, n - a - 1)
``` | instruction | 0 | 98,909 | 17 | 197,818 |
No | output | 1 | 98,909 | 17 | 197,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
Submitted Solution:
```
from bisect import bisect_left, bisect_right
class Result:
def __init__(self, index, value):
self.index = index
self.value = value
class BinarySearch:
def __init__(self):
pass
@staticmethod
def greater_than(num: int, func, size: int = 1):
"""Searches for smallest element greater than num!"""
if isinstance(func, list):
index = bisect_right(func, num)
if index == len(func):
return Result(None, None)
else:
return Result(index, func[index])
else:
alpha, omega = 0, size - 1
if func(omega) <= num:
return Result(None, None)
while alpha < omega:
if func(alpha) > num:
return Result(alpha, func(alpha))
if omega == alpha + 1:
return Result(omega, func(omega))
mid = (alpha + omega) // 2
if func(mid) > num:
omega = mid
else:
alpha = mid
@staticmethod
def less_than(num: int, func, size: int = 1):
"""Searches for largest element less than num!"""
if isinstance(func, list):
index = bisect_left(func, num) - 1
if index == -1:
return Result(None, None)
else:
return Result(index, func[index])
else:
alpha, omega = 0, size - 1
if func(alpha) >= num:
return Result(None, None)
while alpha < omega:
if func(omega) < num:
return Result(omega, func(omega))
if omega == alpha + 1:
return Result(alpha, func(alpha))
mid = (alpha + omega) // 2
if func(mid) < num:
alpha = mid
else:
omega = mid
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = sorted(a)
b = sorted(b, reverse=True)
ans = 0
bs = BinarySearch()
c = []
for i in range(n):
val = b[i]
req = x - val - 1
ind = bs.greater_than(req, a).index
if ind is None:break
ind = n - ind
#print(req, ind)
c += [ind]
c = sorted(c)
for i in range(len(c)):
if c[i] >= i + 1:
ans = i + 1
ans2 = 0
c = []
a = a[::-1]
b = b[::-1]
for i in range(n):
val = a[i]
req = x - val - 1
ind = bs.greater_than(req, b).index
if ind is None:break
ind = n - ind
#print(req, ind)
c += [ind]
c = sorted(c)
for i in range(len(c)):
if c[i] >= i + 1:
ans2 = i + 1
print(1, max(ans, ans2))
``` | instruction | 0 | 98,910 | 17 | 197,820 |
No | output | 1 | 98,910 | 17 | 197,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers β the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 β€ n β€ 105; 0 β€ x β€ 2Β·105) β the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 β€ ai β€ 105) β the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 β€ bi β€ 105) β the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad β there are two integers i, j (1 β€ i, j β€ n) such, that ai + bj β₯ x.
Output
Print two space-separated integers β the best and the worst place Vasya could have got on the Olympiad.
Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
Note
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that β {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that β {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#n=int(input())
#arr = list(map(int, input().split()))
n,x= map(int, input().split())
arr = sorted(list(map(int, input().split())))
ls = list(map(int, input().split()))
ls=sorted(ls,reverse=True)
ans=0
for i in range(n):
if arr[i]+ls[i]>=x:
ans+=1
print(1, ans)
``` | instruction | 0 | 98,911 | 17 | 197,822 |
No | output | 1 | 98,911 | 17 | 197,823 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000 | instruction | 0 | 99,405 | 17 | 198,810 |
"Correct Solution:
```
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
team = data[0][2]
player = data[0][1]
t1 = 0
t2 = 0
f1 = 0
f2 = 0
for i in range(1,N):
if data[i][2] == team:
if data[i][1] != player:
if team == 0:
if t1 < ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
t1 = ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2)
f1 = (data[i][0]- data[i-1][0])/60
if t1 == ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
if f1 > (data[i][0]- data[i-1][0])/60:
f1 = (data[i][0]- data[i-1][0])/60
if team == 1:
if t2 < ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
t2 = ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2)
f2 = (data[i][0] - data[i-1][0])/60
if t2 == ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
if f2 > (data[i][0]- data[i-1][0])/60:
f2 = (data[i][0]- data[i-1][0])/60
player = data[i][1]
team = data[i][2]
if t1 == 0 :
print(-1,-1)
else:
print(t1,f1)
if t2 == 0:
print(-1,-1)
else:
print(t2,f2)
``` | output | 1 | 99,405 | 17 | 198,811 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000 | instruction | 0 | 99,406 | 17 | 198,812 |
"Correct Solution:
```
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1
for _ in range(n):
l = list(map(int, input().split()))
if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
last = l
elif last[1] != l[1]:
len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
tim= l[0] - last[0]
if l[2] == 0:
if Al <= len:
Al = len
At = tim
elif l[2] == 1:
if Bl <= len:
Bl = len
Bt = tim
last = l
if Al != -1:
print("{0:.10f}".format(round(Al,10)), end = " ")
print("{0:.10f}".format(At/60))
else:
print("-1 -1")
if Bl != -1:
print("{0:.10f}".format(round(Bl,10)), end = " ")
print("{0:.10f}".format(Bt/60))
else:
print("-1 -1")
``` | output | 1 | 99,406 | 17 | 198,813 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000 | instruction | 0 | 99,407 | 17 | 198,814 |
"Correct Solution:
```
import math
n = int(input())
prev = list(map(int, input().split()))
max_disA = -1
max_disB = -1
min_timeA = 10**9
min_timeB = 10**9
for _ in range(n-1):
curr = list(map(int, input().split()))
if prev[1] != curr[1] and prev[2] == curr[2]:
dis = math.sqrt((prev[3] - curr[3])**2 + (prev[4] - curr[4])**2)
if max_disA < dis and prev[2] == 0:
max_disA = dis
min_timeA = curr[0] - prev[0]
elif max_disB < dis and prev[2] == 1:
max_disB = dis
min_timeB = curr[0] - prev[0]
elif dis == max_disA and prev[2] == 0 and min_timeA > curr[0] - prev[0]:
max_disA = dis
min_timeA = curr[0] - prev[0]
elif dis == max_disB and prev[2] == 1 and min_timeB > curr[0] - prev[0]:
max_disB = dis
min_timeB = curr[0] - prev[0]
prev = curr
if max_disA == -1:
print(-1, -1)
else:
print(max_disA, min_timeA / 60)
if max_disB == -1:
print(-1, -1)
else:
print(max_disB, min_timeB / 60)
``` | output | 1 | 99,407 | 17 | 198,815 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000 | instruction | 0 | 99,408 | 17 | 198,816 |
"Correct Solution:
```
import math
n = int(input())
prev = list(map(int, input().split()))
max_disA = -1
max_disB = -1
min_timeA = 10**9
min_timeB = 10**9
for _ in range(n-1):
curr = list(map(int, input().split()))
if prev[1] != curr[1] and prev[2] == curr[2]:
dis = math.sqrt((prev[3] - curr[3])**2 + (prev[4] - curr[4])**2)
if max_disA < dis and prev[2] == 0:
max_disA = dis
min_timeA = curr[0] - prev[0]
elif max_disB < dis and prev[2] == 1:
max_disB = dis
min_timeB = curr[0] - prev[0]
elif dis == max_disA and prev[2] == 0 and min_timeA > curr[0] - prev[0]:
max_disA = dis
min_timeA = curr[0] - prev[0]
elif dis == max_disB and prev[2] == 0 and min_timeB > curr[0] - prev[0]:
max_disB = dis
min_timeB = curr[0] - prev[0]
prev = curr
if max_disA == -1:
print(-1, -1)
else:
print(max_disA, min_timeA / 60)
if max_disB == -1:
print(-1, -1)
else:
print(max_disB, min_timeB / 60)
``` | output | 1 | 99,408 | 17 | 198,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000
Submitted Solution:
```
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1
for _ in range(n):
l = list(map(int, input().split()))
if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
last = l
elif last[1] != l[1]:
len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
tim= l[0] - last[0]
if l[2] == 0:
if At < tim: At = tim
if Al < len: Al = len
elif l[2] == 1:
if Bt < tim: Bt = tim
if Bl < len: Bl = len
last = l
if Al != -1:
print("{}".format(Al), end = " ")
print("{}".format(At/60))
else:
print("-1 -1")
if Bl != -1:
print("{}".format(Bl), end = " ")
print("{}".format(Bt/60))
else:
print("-1 -1")
``` | instruction | 0 | 99,409 | 17 | 198,818 |
No | output | 1 | 99,409 | 17 | 198,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000
Submitted Solution:
```
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1
for _ in range(n):
l = list(map(int, input().split()))
if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
last = l
elif last[1] != l[1]:
len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
tim= l[0] -last[0]
if l[2] == 0:
if At < tim: At = tim
if Al < len: Al = len
elif l[2] == 1:
if Bt < tim: Bt = tim
if Bl < len: Bl = len
if Al != -1:
print("{0:.8f}".format(Al), end = " ")
print("{0:.8f}".format(At/60))
else:
print("-1 -1")
if Bl != -1:
print("{0:.8f}".format(Bl), end = " ")
print("{0:.8f}".format(Bt/60))
else:
print("-1 -1")
``` | instruction | 0 | 99,410 | 17 | 198,820 |
No | output | 1 | 99,410 | 17 | 198,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000
Submitted Solution:
```
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1
for _ in range(n):
l = list(map(int, input().split()))
if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
last = l
elif last[1] != l[1]:
len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
tim= l[0] - last[0]
if l[2] == 0:
if Al <= len:
Al = len
At = tim
elif l[2] == 1:
if Bl <= len:
Bl = len
Bl = tim
last = l
if Al != -1:
print("{0:.10f}".format(round(Al,10)), end = " ")
print("{0:.10f}".format(At/60))
else:
print("-1 -1")
if Bl != -1:
print("{0:.10f}".format(round(Bl,10)), end = " ")
print("{0:.10f}".format(Bt/60))
else:
print("-1 -1")
``` | instruction | 0 | 99,411 | 17 | 198,822 |
No | output | 1 | 99,411 | 17 | 198,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
We played an AI soccer match between Country A and Country B. You have a table that records the player who had the ball at a certain time and its position. The table consists of N rows, and the i-th row from the top consists of the following elements.
* Number of frames f_i
* The uniform number of the player who has the ball a_i
* The team to which the player belongs t_i
* Coordinates representing the player's position x_i, y_i
The number of frames is an integer that is set to 0 at the start time of the game and is incremented by 1 every 1/60 second. For example, just 1.5 seconds after the game starts, the number of frames is 90. The uniform number is an integer uniquely assigned to 11 players in each team. Furthermore, in two consecutive records in the table, when players with different numbers on the same team have the ball, a "pass" is made between them. Frames that do not exist in the recording need not be considered.
Now, as an engineer, your job is to find the distance of the longest distance (Euclidean distance) between the players of each team and the time it took. If there are multiple paths with the longest distance, output the one with the shortest time.
input
The input is given in the following format. When t_i = 0, it represents country A, and when t_i = 1, it represents country B.
N
f_0 a_0 t_0 x_0 y_0
...
f_ {Nβ1} a_ {Nβ1} t_ {Nβ1} x_ {Nβ1} y_ {Nβ1}
Constraint
* All inputs are integers
* 1 \ β€ N \ β€ 100
* 0 \ β€ f_i \ lt f_ {i + 1} \ β€ 324 \,000
* 1 \ β€ a_i \ β€ 11
* t_i = 0,1
* 0 \ β€ x_i \ β€ 120
* 0 \ β€ y_i \ β€ 90
output
Output the distance and time taken for the longest path in country A and the distance and time taken for the longest path in country B on one line each. Time is in seconds, and absolute errors of 10 ^ {β3} or less are allowed for both distance and time. If the pass has never been made, output -1 for both.
sample
Sample input 1
Five
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Sample output 1
5.00000000 1.00000000
1.41421356 0.20000000
Country A had a 5 length path at 30 frames and 60 frames = 1 second, and Country B had a β2 length path at 120 frames and 12 frames = 0.2 seconds. These are the longest paths for each.
Sample input 2
2
0 1 0 0 0
10 1 1 0 0
Sample output 2
-1 -1
-1 -1
Sample input 3
3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
Sample output 3
1.4142135624 0.1666666667
-1 -1
Sample input 4
3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
Sample output 4
2.8284271247 0.5000000000
-1 -1
Example
Input
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
Output
5.00000000 1.00000000
1.41421356 0.20000000
Submitted Solution:
```
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1
for _ in range(n):
l = list(map(int, input().split()))
if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
last = l
elif last[1] != l[1]:
len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
tim= l[0] - last[0]
if l[2] == 0:
if At < tim: At = tim
if Al < len: Al = len
elif l[2] == 1:
if Bt < tim: Bt = tim
if Bl < len: Bl = len
last = l
if Al != -1:
print("{0:.10f}".format(Al), end = " ")
print("{0:.10f}".format(At/60))
else:
print("-1 -1")
if Bl != -1:
print("{0:.10f}".format(Bl), end = " ")
print("{0:.10f}".format(Bt/60))
else:
print("-1 -1")
``` | instruction | 0 | 99,412 | 17 | 198,824 |
No | output | 1 | 99,412 | 17 | 198,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | instruction | 0 | 99,712 | 17 | 199,424 |
Tags: implementation
Correct Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
cat=''.join
catn='\n'.join
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
pos={}
pts={}
t=ri()
for _ in range(t):
n=ri()
for i in range(n):
s=rl()
if s not in pos:
pos[s]=[0]*50
pts[s]=0
pos[s][i]-=1
if i<10:
pts[s]-=[25, 18, 15, 12, 10, 8, 6, 4, 2, 1][i]
by_pts=sorted(pts,key=lambda x:(pts[x],pos[x]))[0]
by_pos=sorted(pts,key=lambda x:(pos[x][0],pts[x],pos[x]))[0]
print(by_pts)
print(by_pos)
``` | output | 1 | 99,712 | 17 | 199,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | instruction | 0 | 99,713 | 17 | 199,426 |
Tags: implementation
Correct Solution:
```
import sys
ht = {}
r = [[0 for i in range(50)] for j in range(50)]
t = int(sys.stdin.readline().strip())
for i in range(t):
n = int(sys.stdin.readline().strip())
for j in range(n):
name = sys.stdin.readline().strip()
if name not in ht:
ht[name] = len(ht)
r[ht[name]][j] += 1
d1, d2 = [], []
pt = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
for name in ht:
r_ = r[ht[name]]
sc = 0
for i in range(len(pt)):
sc += r_[i] * pt[i]
d1.append((name, [sc] + r_))
d2.append((name, r_[:1] + [sc] + r_[1:]))
d1 = sorted(d1, key=lambda data: data[1], reverse=True)
d2 = sorted(d2, key=lambda data: data[1], reverse=True)
print(d1[0][0])
print(d2[0][0])
``` | output | 1 | 99,713 | 17 | 199,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | instruction | 0 | 99,714 | 17 | 199,428 |
Tags: implementation
Correct Solution:
```
t, q = {}, [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
for i in range(int(input())):
for j in range(int(input())):
p = input()
if not p in t: t[p] = [0] * 52
if j < 10: t[p][0] += q[j]
t[p][j + 1] += 1
print(max(t.items(), key = lambda x: x[1])[0])
for p in t: t[p][1], t[p][0] = t[p][0], t[p][1]
print(max(t.items(), key = lambda x: x[1])[0])
``` | output | 1 | 99,714 | 17 | 199,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | instruction | 0 | 99,715 | 17 | 199,430 |
Tags: implementation
Correct Solution:
```
def solution():
n = int(input())
# number of races
scores = {}
points = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
# the scores of drivers
places = {}
# the places of drivers
for i in range(n):
m = int(input())
# number of drivers participating in the race
for j in range(m):
name = input()
if name in scores:
if j < len(points):
scores[name] += points[j]
else:
if j < len(points):
scores[name] = points[j]
else:
scores[name] = 0
# count the scores of each race
if name in places:
places[name][j] += 1
else:
places[name] = [0 for _ in range(50)]
places[name][j] += 1
# count the places of each race
# print(scores)
# print(places)
origin_scores = scores
scores = sorted(list(scores.items()), key=lambda s: s[1], reverse=True)
places = sorted(list(places.items()), key=lambda s: tuple(s[1][i] for i in range(50)), reverse=True)
# print(scores)
# print(places)
scores_index = {}
for i in range(len(scores)):
scores_index[scores[i][0]] = i
places_index = {}
for i in range(len(places)):
places_index[places[i][0]] = i
# find the winner of score system
max_score = scores[0][1]
candidates = []
for i in scores:
if i[1] == max_score:
candidates.append((i[0], places_index[i[0]]))
candidates.sort(key=lambda s: s[1])
winner1 = candidates[0][0]
# find the winner of place system
candidates = [places[0][0]]
for i in range(1, len(places)):
if places[i][1][0] != places[0][1][0]:
break
candidates.append(places[i][0])
for i in range(len(candidates)):
candidates[i] = (candidates[i], scores_index[candidates[i]])
candidates.sort(key=lambda s: s[1])
max_score = origin_scores[candidates[0][0]]
candidates1 = []
for i in range(len(candidates)):
if origin_scores[candidates[i][0]] == max_score:
candidates1.append(candidates[i][0])
for i in range(len(candidates1)):
candidates1[i] = (candidates1[i], places_index[candidates1[i]])
candidates1.sort(key=lambda s: s[1])
winner2 = candidates1[0][0]
print(winner1)
print(winner2)
if __name__ == "__main__":
solution()
``` | output | 1 | 99,715 | 17 | 199,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | instruction | 0 | 99,716 | 17 | 199,432 |
Tags: implementation
Correct Solution:
```
t, q = {}, [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]
for i in range(int(input())):
for j in range(int(input())):
p = input()
if not p in t: t[p] = [0] * 52
if j < 10: t[p][0] += q[j]
t[p][j + 1] += 1
print(max(t.items(), key = lambda x: x[1])[0])
for p in t: t[p][1], t[p][0] = t[p][0], t[p][1]
print(max(t.items(), key = lambda x: x[1])[0])
# Made By Mostafa_Khaled
``` | output | 1 | 99,716 | 17 | 199,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare.
Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.
You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.
Input
The first line contain integer t (1 β€ t β€ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 β€ n β€ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.
Output
Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.
Examples
Input
3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel
Output
Vettel
Hamilton
Input
2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees
Output
Prost
Prost
Note
It is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50. | instruction | 0 | 99,717 | 17 | 199,434 |
Tags: implementation
Correct Solution:
```
n = int(input())
lis=[25,18,15,12, 10, 8, 6, 4, 2, 1]+[0]*52
li=dict()
for i in range(n):
for j in range(int(input())):
player = input()
if player not in li:
li[player]=[0]*51+[player]
li[player][0] +=lis[j]
li[player][j+1] +=1
#print(li)
li = sorted(li.values(),reverse=True)
print(li[0][51])
print(sorted(li,key=lambda l:l[1],reverse=True)[0][51])
``` | output | 1 | 99,717 | 17 | 199,435 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.