message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6 | instruction | 0 | 105,735 | 8 | 211,470 |
Tags: brute force, implementation
Correct Solution:
```
input()
heights = list(map(int, input().split()))
max_cnt = 0
for i in range(0, len(heights)):
cur_h = heights[i]
cnt = 1
if i > 0:
for j in range(i - 1, -1, -1):
if heights[j] <= cur_h:
cnt += 1
cur_h = heights[j]
else:
break
cur_h = heights[i]
if i < len(heights) - 1:
for j in range(i + 1, len(heights)):
if heights[j] <= cur_h:
cnt += 1
cur_h = heights[j]
else:
break
if cnt > max_cnt:
max_cnt = cnt
print(max_cnt)
``` | output | 1 | 105,735 | 8 | 211,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6 | instruction | 0 | 105,736 | 8 | 211,472 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
height = list(map(int,input().split()))
ans = 1
for i in range(n):
count = 1
for j in range(i,0,-1):
if (height[j-1] <= height[j]):
count += 1
else:
break
for j in range(i,n-1):
if (height[j+1] <= height[j]):
count += 1
else:
break
ans = max(ans,count)
print(ans)
``` | output | 1 | 105,736 | 8 | 211,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6 | instruction | 0 | 105,737 | 8 | 211,474 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
lst = list(map(int,input().split()))
mp = {}
for i in range(n):
lef = i-1
rig = i+1
num = 1
while lef >= 0:
if lst[lef] <= lst[lef+1]:
num+=1
lef-=1
else:
break
while rig < n:
if lst[rig] <= lst[rig-1]:
num+=1
rig+=1
else:
break
mp[i] = num
print(max(mp.values()))
``` | output | 1 | 105,737 | 8 | 211,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n=int(input())
b=[]
l=list(map(int,input().split()))
if n>2:
for i in range(n):
count=0
ref=l[i]
for j in range(i-1,-1,-1):
if ref>=l[j] and i!=0 :
count+=1
ref=l[j]
# print(ref,j,l[i],i,"loop1")
else:
break
ref=l[i]
for j in range(i+1,n):
if ref>=l[j] and i!=n-1:
count+=1
ref=l[j]
# print(ref,j,l[i],"loop2")
else:
break
#print("new")
#print(count)
b.append(count)
print(max(b)+1)
else:
print(n)
'''
8
1 2 1 1 1 3 3 4'''
``` | instruction | 0 | 105,738 | 8 | 211,476 |
Yes | output | 1 | 105,738 | 8 | 211,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n = int(input())
t = list(map(int, input().split()))
a, b = [0] * n, [0] * n
for i in range(1, n):
if t[i] >= t[i - 1]: a[i] = a[i - 1] + 1
if t[- i] <= t[- 1 - i]: b[- i - 1] = b[- i] + 1
print(max((a[i] + b[i] + 1) for i in range(n)))
``` | instruction | 0 | 105,739 | 8 | 211,478 |
Yes | output | 1 | 105,739 | 8 | 211,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
import sys
def localmin():
def recur(l, low, high, n):
mid = (low + high) // 2
while low != high:
if l[mid] == 0 or l[mid - 1] == 0 or l[mid + 1] == 0:
mid += 1
continue
# print(l[mid])
if (mid > 0 and l[mid - 1] < l[mid]) or (mid < n - 1 and l[mid] > l[mid + 1]):
low = mid + 1
mid = (low + high) // 2
# mid = (low + high) //2
elif (mid < n - 1 and l[mid] < l[mid + 1]) or (mid > 0 and l[mid - 1] > l[mid]):
high = mid
mid = (low + high) // 2
# print(l[low])
return low + 1
# mid = (low + high) // 2
# if (mid == 0 or l[mid - 1] > l[mid]) and (mid == n - 1 or l[mid + 1] > l[mid]):
# return mid + 1
# elif (mid > 0 and l[mid - 1] < l[mid]):
# return recur(l, low, mid, n)
# return recur(l, mid + 1, high, n)
num = int(input())
l = [0] * num
for i in range(1, num + 1):
print('?', i, sep=' ')
sys.stdout.flush()
l[int(input()) - 1] = i
if i == 101:
break
return '! ' + str(recur(l, 0, len(l) - 1, len(l) - 1))
# print(localmin())
def painting():
num = int(input())
l = input().split()
pos = 0
c = 0
# pos1 = pos
l1last = ''
llast = ''
while pos < num:
if l[pos] != llast:
llast = l[pos]
pos1 = pos + 1
c += 1
while pos1 < num and l[pos1] == llast:
pos1 += 1
try:
if pos1 - pos != 1 and l[pos1] != l1last:
c += 1
l1last = l[pos1 - 1]
except:
return c + 1
pos = pos1
return c
# print(painting())
def arena():
case = int(input())
for _ in range(case):
num = int(input())
l = sorted(list(map(int, input().split())))
minn, *l = l
for i, v in enumerate(l):
if v > minn:
print(len(l) - i)
break
else:
print(0)
# arena()
def catcycle():
case = int(input())
for _ in range(case):
spots, hour = map(int, input().split())
if spots % 2:
a = spots
b = 1
hour %= (spots * (spots // 2) + (spots // 2) - 1)
for i in range(1, hour):
a -= 1
if (b + 1) % spots == a:
b += 2
else:
b += 1
if b > spots:
b = b % spots
if a < 1:
a = spots
print(b)
# while hour >= 0:
# a -= 1
# if (b + 1) % spots == a:
# b += 2
# else:
# b += 1
# if b > spots:
# b = b % spots
# if a < 1:
# a = spots
# hour -= 1
# b %= spots
# print(b if b else 1)
else:
spot = hour % spots
print(spot if spot else spots)
# catcycle()
def vanyafence():
f, maxh = map(int, input().split())
res = 0
for i in input().split():
if int(i) > maxh:
res += 1
res += 1
return res
# print(vanyafence())
def antonanddanik():
num = input()
s = input()
ac = s.count("A")
dc = s.count('D')
if dc == ac:
return 'Friendship'
return 'Anton' if ac > dc else 'Danik'
# print(antonanddanik())
def weight():
a, b = map(int, input().split())
for i in range(1, 10000):
a *= 3
b *= 2
if a > b:
return i
# print(weight())
def petyarain():
num = int(input())
l = input().split()
ans = 0
for i in range(num):
c = 1
for i1 in range(i-1,-1,-1):
if int(l[i1]) > int(l[i1+1]):
break
c += 1
for i1 in range(i+1,num):
if int(l[i1-1]) < int(l[i1]):
break
c += 1
ans = max(ans,c)
return ans
print(petyarain())
``` | instruction | 0 | 105,740 | 8 | 211,480 |
Yes | output | 1 | 105,740 | 8 | 211,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n = int(input())
h = *map(int, input().split()),
count = 1
for i in range(n):
x = y = h[i]
k = j = i
while j - 1 >= 0 and h[j - 1] <= x:
j -= 1
x = h[j]
while k < n and h[k] <= y:
y = h[k]
k += 1
count = max(count, k - j)
print(count)
``` | instruction | 0 | 105,741 | 8 | 211,482 |
Yes | output | 1 | 105,741 | 8 | 211,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
'''input
1
2
'''
n = int(input())
h = list(map(int, input().split()))
m = 0
for x in range(n):
i, j = x, x
while i > 1:
if h[i-1] <= h[i]:
i -= 1
else:
break
while j < n-1:
if h[j+1] <= h[j]:
j += 1
else:
break
m = max(m, j-i)
print(m+1)
``` | instruction | 0 | 105,742 | 8 | 211,484 |
No | output | 1 | 105,742 | 8 | 211,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
b1=[1]*(n)
b2=[0]*(n)
i=1
while i<(len(a)):
if a[i]>=a[i-1]:
b1[i]=b1[i]+b1[i-1]
j=i
while(j<(len(a))):
if j<len(a)-1 and a[j]>=a[j+1] and a[j]<=a[i]:
j+=1
flag=1
b2[i]+=1
else:
break
i+=1
max1=0
for i in range(n):
if max1<b1[i]+b2[i]:
max1=b1[i]+b2[i]
print(max1)
``` | instruction | 0 | 105,743 | 8 | 211,486 |
No | output | 1 | 105,743 | 8 | 211,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n=int(input())
sum=0
a=[int(i) for i in input().split()]
if(len(a)==1):
print(1)
else:
for i in range(0,len(a)):
if(i==len(a)-1):
d=a[0:i]
e=max(d)
if(e<=a[i]):
pass
else:
sum=sum+(e-a[i])
else:
d=a[0:i]
e=a[i+1:]
if(len(d)>=1):
f=max(d)
else:
f=0
if(len(e)>=1):
g=max(e)
else:
g=0
if(f!=0 and g!=0):
h=min(f,g)
else:
h=max(f,g)
if(h<=a[i]):
sum=sum+0
else:
sum=sum+(h-a[i])
print(sum)
``` | instruction | 0 | 105,744 | 8 | 211,488 |
No | output | 1 | 105,744 | 8 | 211,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n = int(input())
heights = list(map(int, input().split()))
if n == 1:
print(1)
else:
max_val = 0
for i in range(n):
current = 0
for j in range(i - 1, 0, -1):
if heights[j] > heights[j + 1]:
break
current += 1
for j in range(i, n):
if heights[j] > heights[j - 1]:
break
current += 1
max_val = max(max_val, current)
print(max_val + 1)
``` | instruction | 0 | 105,745 | 8 | 211,490 |
No | output | 1 | 105,745 | 8 | 211,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image> | instruction | 0 | 105,747 | 8 | 211,494 |
Tags: constructive algorithms
Correct Solution:
```
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0
p = [0] * 9
p[1] = 3, 1, 3, 2
p[2] = 4, 1, 4, 2
p[3] = 4, 2, 5, 2
p[4] = 4, 3, 5, 3
p[5] = 1, 3, 2, 3
p[6] = 1, 4, 2, 4
p[7] = 2, 4, 2, 5
p[8] = 3, 4, 3, 5
for i in range(L):
bit = a[L - i - 1]
for j in range(1, 9):
if not f[bit][j]: continue
x1, y1, x2, y2 = p[j]; D = 2 * i
x1 += D; y1 += D; x2 += D; y2 += D
if corr(x2, y2): ans.append((x1, y1, x2, y2))
for i in range(L - 1):
x1, y1 = 5 + i * 2, 1 + i * 2
x2, y2 = 1 + i * 2, 5 + i * 2
ans.append((x1, y1, x1 + 1, y1))
ans.append((x1, y1 + 1, x1 + 1, y1 + 1))
ans.append((x2, y2, x2, y2 + 1))
ans.append((x2 + 1, y2, x2 + 1, y2 + 1))
print(n, m)
print(len(ans))
[print(*i) for i in ans]
``` | output | 1 | 105,747 | 8 | 211,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][5] = f[5][6] = f[5][1] = 0
p = [0] * 9
p[1] = 3, 1, 3, 2
p[2] = 4, 1, 4, 2
p[3] = 4, 2, 5, 2
p[4] = 4, 3, 5, 3
p[5] = 1, 3, 2, 3
p[6] = 1, 4, 2, 4
p[7] = 2, 4, 2, 5
p[8] = 3, 4, 3, 5
for i in range(L):
bit = a[i]
for j in range(1, 9):
if not f[bit][j]: continue
x1, y1, x2, y2 = p[j]; D = 2 * i
x1 += D; y1 += D; x2 += D; y2 += D
if corr(x2, y2): ans.append((x1, y1, x2, y2))
for i in range(L - 1):
x1, y1 = 5 + i * 2, 1 + i * 2
x2, y2 = 1 + i * 2, 5 + i * 2
ans.append((x1, y1, x1 + 1, y1))
ans.append((x1, y1 + 1, x1 + 1, y1 + 1))
ans.append((x2, y2, x2, y2 + 1))
ans.append((x2 + 1, y2, x2 + 1, y2 + 1))
print(n, m)
print(len(ans))
[print(*i) for i in ans]
``` | instruction | 0 | 105,748 | 8 | 211,496 |
No | output | 1 | 105,748 | 8 | 211,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
for i in range(L - 1):
x1, y1 = 5 + i * 2, 1 + i * 2
x2, y2 = 1 + i * 2, 5 + i * 2
ans.append((x1, y1, x1 + 1, y1))
ans.append((x1, y1 + 1, x1 + 1, y1 + 1))
ans.append((x2, y2, x2, y2 + 1))
ans.append((x2 + 1, y2, x2 + 1, y2 + 1))
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][5] = f[5][6] = f[5][1] = 0
p = [0] * 9
p[1] = 3, 1, 3, 2
p[2] = 4, 1, 4, 2
p[3] = 4, 2, 5, 2
p[4] = 4, 3, 5, 3
p[5] = 1, 3, 2, 3
p[6] = 1, 4, 2, 4
p[7] = 2, 4, 2, 5
p[8] = 3, 4, 3, 5
for i in range(L):
bit = a[i]
for j in range(1, 9):
if not f[bit][j]: continue
x1, y1, x2, y2 = p[j]; D = 2 * i
x1 += D; y1 += D; x2 += D; y2 += D
if corr(x2, y2): ans.append((x1, y1, x2, y2))
print(n, m)
print(len(ans))
[print(*i) for i in ans]
``` | instruction | 0 | 105,749 | 8 | 211,498 |
No | output | 1 | 105,749 | 8 | 211,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
print("3 2 0");
``` | instruction | 0 | 105,750 | 8 | 211,500 |
No | output | 1 | 105,750 | 8 | 211,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
"""
Codeforces Round 372 Div 1 Problem D
Author : chaotic_iak
Language: Python 3.5.2
"""
################################################### SOLUTION
sol = {
1: (3, 3, 3, 3), 2: (2, 3, 3, 3), 3: (2, 2, 3, 3), 4: (2, 2, 2, 3),
5: (2, 2, 2, 2), 6: (2, 1, 3, 3), 7: (0, 2, 3, 3), 8: (1, 0, 3, 3),
9: (3, 2, 2, 3), 10: (2, 2, 1, 3), 11: (0, -1, 3, 3), 12: (1, 1, 2, 2),
13: (1, 1, 0, 3), 14: (2, 1, 2, 2), 15: (0, 3, 1, 3), 16: (2, 1, 0, 3),
17: (3, 3, 1, 3), 18: (0, 1, 0, 3), 19: (2, 3, 3, 2), 20: (0, 2, 2, 1),
21: (2, 0, 0, 3), 22: (1, -1, 0, 3), 23: (1, 1, 3, 0), 24: (2, 2, 3, 1),
25: (2, -1, 0, 3), 26: (2, -1, 3, 2), 27: (3, -1, 1, 3), 28: (1, 0, 3, 0),
29: (-1, 2, 1, 2), 30: (3, -1, 0, 3), 31: (3, 1, 1, 1), 32: (-1, 2, 2, -1),
33: (3, 1, 2, 0), 34: (0, 0, 1, -1), 35: (0, -1, 2, 0), 36: (3, 3, 2, -1),
37: (-1, 3, 1, 2), 38: (2, 3, 1, 0), 39: (1, 0, -1, 0), 40: (3, 2, 0, 1),
41: (2, -1, 0, 2), 42: (1, -1, 0, 1), 43: (3, 0, 1, 1), 44: (3, 2, 0, -1),
45: (3, -1, 2, 0), 46: (0, -1, -1, 1), 47: (-1, 0, 1, 1), 48: (3, 2, -1, -1),
49: (0, -1, -1, 0), 50: (2, -1, 0, 1), 51: (-1, 0, 1, -1), 52: (3, 0, -1, 1),
53: (2, -1, 0, 0), 54: (3, -1, 1, -1), 55: (-1, 0, 0, 0), 56: (-1, 0, -1, 1),
57: (-1, -1, 1, 0), 58: (3, -1, 0, 1), 59: (-1, 3, -1, 0), 60: (-1, 3, -1, -1),
61: (3, -1, -1, 1), 62: (3, -1, 0, -1), 65: (-1, -1, -1, 1), 66: (3, -1, -1, -1),
69: (-1, -1, -1, 0)
}
supersol = {
0: [(3, 4, 3, 5), (4, 4, 4, 5)],
63: [(0, 3, 0, 4), (3, 3, 3, 4)],
64: [(0, 2, 0, 3), (1, 1, 1, 2)],
67: [(1, 0, 1, 1), (1, 4, 2, 4)],
68: [(1, 0, 1, 1), (0, 3, 1, 3)]
}
def base70(n):
res = []
while n:
res.append(n % 70)
n //= 70
return list(reversed(res))
def main():
t, = read()
t = base70(t)
t = [0]*(10-len(t)) + t
walls = []
for i in range(10):
walls.append((5*i, 4, 5*i, 5))
walls.append((5*i+1, 4, 5*i+1, 5))
walls.append((5*i+2, 4, 5*i+2, 5))
if i != 9:
walls.append((5*i+4, 1, 5*i+5, 1))
walls.append((5*i+4, 2, 5*i+5, 2))
walls.append((5*i+4, 3, 5*i+5, 3))
walls.append((5*i+4, 4, 5*i+5, 4))
if t[i] in {0, 63, 64, 67, 68}:
walls.append((5*i+2, 5, 5*i+3, 5))
walls.append((5*i+3, 5, 5*i+3, 6))
walls.extend((5*i+n[0], n[1], 5*i+n[2], n[3]) for n in supersol[t[i]])
else:
walls.append((5*i+3, 4, 5*i+3, 5))
solcurr = sol[t[i]]
for n in range(1,5):
if solcurr[n-1] == -1: continue
walls.append((5*i+solcurr[n-1], n, 5*i+1+solcurr[n-1], n))
walls.append((4, 5, 4, 6))
for i in range(1, 9):
for j in range(5, 5+4*i):
walls.append((5*i+4, j, 5*i+5, j))
for j in range(5):
walls.append((5*i+j, 6+4*i, 5*i+j, 7+4*i))
walls = set(walls)
print(50, 46)
print(len(walls))
for w in walls:
print(w[0]+1, w[1]+1, w[2]+1, w[3]+1)
#################################################### HELPERS
def read(typ=int):
# None: String, non-split
# Not None: Split
input_line = input().strip()
if typ is None:
return input_line
return list(map(typ, input_line.split()))
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
write(main())
``` | instruction | 0 | 105,751 | 8 | 211,502 |
No | output | 1 | 105,751 | 8 | 211,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!
There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors.
The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that:
1. Number x lies on the interval from li to ri inclusive (li β€ x β€ ri).
2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti.
For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them.
Input
The first line contains numbers n and q (1 β€ n, q β€ 105). Next n lines contain pairs of numbers ai, bi (1 β€ ai, bi β€ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 β€ li β€ ri β€ n, 0 β€ ti β€ 106). All input numbers are integers.
Output
For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line.
Examples
Input
5 4
4 1
3 5
6 2
3 5
6 5
1 5 2
1 3 5
1 1 0
1 5 0
Output
5
2
1
5
Input
5 4
6 1
5 1
2 5
4 3
6 1
2 4 1
3 4 5
1 4 5
1 2 0
Output
3
3
3
1
Submitted Solution:
```
from sys import stdin, stdout
EPS = 10 ** (-20)
def merge(ind):
if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 0
elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2 + 1][0])
i = 0
j = 1
elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 1
else:
tree[ind].append(tree[ind * 2 + 1][0])
i = 1
j = 1
time = 10 ** 6 + 6
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]):
t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2])
if t1 < t2:
tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
else:
tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
while i < len(tree[ind * 2]):
if (tree[ind * 2][i][2] > tree[ind][-1][2] or tree[ind * 2][i][1] + tree[ind * 2][i][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time):
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
while j < len(tree[ind * 2 + 1]):
if (tree[ind * 2 + 1][j][2] > tree[ind][-1][2] or tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time):
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]), tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
def get(l, r, lb, rb, ind, time):
if l == lb and r == rb:
l, r = -1, len(tree[ind])
while r - l > 1:
m = (r + l) // 2
if tree[ind][m][0] <= time + EPS:
l = m
else:
r = m
if l == -1:
return 0
else:
return tree[ind][l]
m = (lb + rb) // 2
first, second = 0, 0
if l <= m:
first = get(l, min(m, r), lb, m, ind * 2, time)
if r > m:
second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time)
if not first:
return second
elif not second:
return first
else:
return max(second, first, key = lambda x: x[1] + x[2] * time)
n, q = map(int, stdin.readline().split())
start = []
rise = []
for i in range(n):
a, b = map(int, stdin.readline().split())
start.append(a)
rise.append(b)
power = 1
while power <= n:
power *= 2
tree = [[] for i in range(power * 2)]
for i in range(n):
tree[power + i].append((0, start[i], rise[i], i + 1))
for i in range(power - 1, 0, -1):
if not tree[i * 2]:
tree[i] = tree[i * 2 + 1]
elif not tree[i * 2 + 1]:
tree[i] = tree[i * 2]
else:
merge(i)
for i in range(q):
l, r, t = map(int, stdin.readline().split())
stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n')
``` | instruction | 0 | 105,846 | 8 | 211,692 |
No | output | 1 | 105,846 | 8 | 211,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!
There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors.
The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that:
1. Number x lies on the interval from li to ri inclusive (li β€ x β€ ri).
2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti.
For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them.
Input
The first line contains numbers n and q (1 β€ n, q β€ 105). Next n lines contain pairs of numbers ai, bi (1 β€ ai, bi β€ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 β€ li β€ ri β€ n, 0 β€ ti β€ 106). All input numbers are integers.
Output
For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line.
Examples
Input
5 4
4 1
3 5
6 2
3 5
6 5
1 5 2
1 3 5
1 1 0
1 5 0
Output
5
2
1
5
Input
5 4
6 1
5 1
2 5
4 3
6 1
2 4 1
3 4 5
1 4 5
1 2 0
Output
3
3
3
1
Submitted Solution:
```
from sys import stdin, stdout
from decimal import Decimal
EPS = Decimal(10) ** Decimal(-30)
def merge(ind):
if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 0
elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2 + 1][0])
i = 0
j = 1
elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 1
else:
tree[ind].append(tree[ind * 2 + 1][0])
i = 1
j = 1
time = Decimal(10 ** 6 + 6)
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]):
t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2])
if t1 < t2:
tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
else:
tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
while i < len(tree[ind * 2]):
if (tree[ind * 2][i][2] > tree[ind][-1][2] or tree[ind * 2][i][1] + tree[ind * 2][i][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time):
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
while j < len(tree[ind * 2 + 1]):
if (tree[ind * 2 + 1][j][2] > tree[ind][-1][2] or tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time):
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]), tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
def get(l, r, lb, rb, ind, time):
if l == lb and r == rb:
l, r = -1, len(tree[ind])
while r - l > 1:
m = (r + l) // 2
if tree[ind][m][0] <= time + EPS:
l = m
else:
r = m
if l == -1:
return 0
else:
return tree[ind][l]
m = (lb + rb) // 2
first, second = 0, 0
if l <= m:
first = get(l, min(m, r), lb, m, ind * 2, time)
if r > m:
second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time)
if not first:
return second
elif not second:
return first
else:
return max(second, first, key = lambda x: (x[1] + x[2] * time, x[2]))
n, q = map(int, stdin.readline().split())
start = []
rise = []
for i in range(n):
a, b = map(int, stdin.readline().split())
start.append(a)
rise.append(b)
power = 1
while power <= n:
power *= 2
tree = [[] for i in range(power * 2)]
for i in range(n):
tree[power + i].append((Decimal(0), Decimal(start[i]), Decimal(rise[i]), i + 1))
for i in range(power - 1, 0, -1):
if not tree[i * 2]:
tree[i] = tree[i * 2 + 1]
elif not tree[i * 2 + 1]:
tree[i] = tree[i * 2]
else:
merge(i)
for i in range(q):
l, r, t = map(int, stdin.readline().split())
stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n')
``` | instruction | 0 | 105,847 | 8 | 211,694 |
No | output | 1 | 105,847 | 8 | 211,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!
There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors.
The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that:
1. Number x lies on the interval from li to ri inclusive (li β€ x β€ ri).
2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti.
For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them.
Input
The first line contains numbers n and q (1 β€ n, q β€ 105). Next n lines contain pairs of numbers ai, bi (1 β€ ai, bi β€ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 β€ li β€ ri β€ n, 0 β€ ti β€ 106). All input numbers are integers.
Output
For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line.
Examples
Input
5 4
4 1
3 5
6 2
3 5
6 5
1 5 2
1 3 5
1 1 0
1 5 0
Output
5
2
1
5
Input
5 4
6 1
5 1
2 5
4 3
6 1
2 4 1
3 4 5
1 4 5
1 2 0
Output
3
3
3
1
Submitted Solution:
```
from sys import stdin, stdout
EPS = 10 ** (-20)
def merge(ind):
if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 0
elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2 + 1][0])
i = 0
j = 1
elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 1
else:
tree[ind].append(tree[ind * 2 + 1][0])
i = 1
j = 1
time = 10 ** 6 + 6
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]):
t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2])
if t1 < t2:
tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
else:
tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
while i < len(tree[ind * 2]):
if (tree[ind * 2][i][2] > tree[ind][-1][2] or tree[ind * 2][i][1] + tree[ind * 2][i][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time):
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
while j < len(tree[ind * 2 + 1]):
if (tree[ind * 2 + 1][j][2] > tree[ind][-1][2] or tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time):
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]), tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
def get(l, r, lb, rb, ind, time):
if l == lb and r == rb:
l, r = -1, len(tree[ind])
while r - l > 1:
m = (r + l) // 2
if tree[ind][m][0] <= time + EPS:
l = m
else:
r = m
if l == -1:
return 0
else:
return tree[ind][l]
m = (lb + rb) // 2
first, second = 0, 0
if l <= m:
first = get(l, min(m, r), lb, m, ind * 2, time)
if r > m:
second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time)
if not first:
return second
elif not second:
return first
else:
return max(second, first, key = lambda x: (x[1] + x[2] * time, x[2]))
n, q = map(int, stdin.readline().split())
start = []
rise = []
for i in range(n):
a, b = map(int, stdin.readline().split())
start.append(a)
rise.append(b)
power = 1
while power <= n:
power *= 2
tree = [[] for i in range(power * 2)]
for i in range(n):
tree[power + i].append((0, start[i], rise[i], i + 1))
for i in range(power - 1, 0, -1):
if not tree[i * 2]:
tree[i] = tree[i * 2 + 1]
elif not tree[i * 2 + 1]:
tree[i] = tree[i * 2]
else:
merge(i)
for i in range(q):
l, r, t = map(int, stdin.readline().split())
stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n')
``` | instruction | 0 | 105,848 | 8 | 211,696 |
No | output | 1 | 105,848 | 8 | 211,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!
There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors.
The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that:
1. Number x lies on the interval from li to ri inclusive (li β€ x β€ ri).
2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti.
For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them.
Input
The first line contains numbers n and q (1 β€ n, q β€ 105). Next n lines contain pairs of numbers ai, bi (1 β€ ai, bi β€ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 β€ li β€ ri β€ n, 0 β€ ti β€ 106). All input numbers are integers.
Output
For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line.
Examples
Input
5 4
4 1
3 5
6 2
3 5
6 5
1 5 2
1 3 5
1 1 0
1 5 0
Output
5
2
1
5
Input
5 4
6 1
5 1
2 5
4 3
6 1
2 4 1
3 4 5
1 4 5
1 2 0
Output
3
3
3
1
Submitted Solution:
```
from sys import stdin, stdout
EPS = 10 ** (-20)
def merge(ind):
if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 0
elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]:
tree[ind].append(tree[ind * 2 + 1][0])
i = 0
j = 1
elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]:
tree[ind].append(tree[ind * 2][0])
i = 1
j = 1
else:
tree[ind].append(tree[ind * 2 + 1][0])
i = 1
j = 1
while i < len(tree[ind * 2]) and (tree[ind * 2][i][2] - tree[ind][-1][2]):
time = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]) + 5
if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
else:
break
while j < len(tree[ind * 2 + 1]) and (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]):
time = (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) + 5
if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
else:
break
while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]):
t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2] + EPS), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2] + EPS)
if t1 < t2:
tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
else:
tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
while i < len(tree[ind * 2]) and (tree[ind * 2][i][2] - tree[ind][-1][2]):
time = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]) + 5
if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time:
i += 1
else:
break
while j < len(tree[ind * 2 + 1]) and (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]):
time = (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) + 5
if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time:
j += 1
else:
break
while i < len(tree[ind * 2]) and tree[ind * 2][i][2] > tree[ind][-1][2]:
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2] + EPS), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3]))
i += 1
while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] > tree[ind][-1][2]:
tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) + EPS, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3]))
j += 1
def get(l, r, lb, rb, ind, time):
if l == lb and r == rb:
l, r = -1, len(tree[ind])
while r - l > 1:
m = (r + l) // 2
if tree[ind][m][0] <= time + EPS:
l = m
else:
r = m
if l == -1:
return 0
else:
return tree[ind][l]
m = (lb + rb) // 2
first, second = 0, 0
if l <= m:
first = get(l, min(m, r), lb, m, ind * 2, time)
if r > m:
second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time)
if not first:
return second
elif not second:
return first
else:
return max(second, first, key = lambda x: x[1] + x[2] * time)
n, q = map(int, stdin.readline().split())
start = []
rise = []
for i in range(n):
a, b = map(int, stdin.readline().split())
start.append(a)
rise.append(b)
power = 1
while power <= n:
power *= 2
tree = [[] for i in range(power * 2)]
for i in range(n):
tree[power + i].append((0, start[i], rise[i], i + 1))
for i in range(power - 1, 0, -1):
if not tree[i * 2]:
tree[i] = tree[i * 2 + 1]
elif not tree[i * 2 + 1]:
tree[i] = tree[i * 2]
else:
merge(i)
for i in range(q):
l, r, t = map(int, stdin.readline().split())
stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n')
``` | instruction | 0 | 105,849 | 8 | 211,698 |
No | output | 1 | 105,849 | 8 | 211,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,850 | 8 | 211,700 |
Tags: binary search, data structures
Correct Solution:
```
import itertools
import operator
from bisect import bisect
def main():
N = int(input())
V = tuple(map(int, input().split()))
T = tuple(map(int, input().split()))
templ = [0] + list(itertools.accumulate(T, operator.add))
M = [0] * (N + 2)
lost = M[:]
for j, v in enumerate(V):
i = bisect(templ, v + templ[j])
M[i] += v + templ[j] - templ[i-1]
lost[i] += 1
F = [0] * (N + 1)
for i in range(N):
F[i+1] += F[i] + 1 - lost[i+1]
print(*[F[i] * T[i-1] + M[i] for i in range(1, N + 1)], sep=' ')
main()
``` | output | 1 | 105,850 | 8 | 211,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,851 | 8 | 211,702 |
Tags: binary search, data structures
Correct Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
N = int(input())
V = alele()
T= alele()
B = [0] + list(accumulate(T))
Ans1 = [0]*(N+2)
Ans2 = [0]*(N+2)
#print(B)
for i in range(N):
x = V[i]
if T[i] < V[i]:
a = bisect.bisect_left(B,x + B[i])
#print(x+B[i],a)
Ans2[i] += 1
#print(i,a)
Ans2[a-1] -= 1
if T[i] < V[i]:
z = B[a-1] - B[i]
zz = V[i] -z
Ans1[a-1] +=zz
#print(zz)
#print(Ans2)
#print(Ans1)
else:
Ans1[i] += V[i]
C = list(accumulate(Ans2))
#print(C)
#print(Ans1)
for i in range(N):
print((C[i]*T[i]) + Ans1[i],end = ' ')
``` | output | 1 | 105,851 | 8 | 211,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,852 | 8 | 211,704 |
Tags: binary search, data structures
Correct Solution:
```
import heapq
heap = []
n = int(input())
V = list(map(int, input().split()))
T = list(map(int, input().split()))
tmp = 0
for i in range(n):
ans = 0
heapq.heappush(heap, tmp+V[i])
while len(heap) and heap[0]<=tmp+T[i]:
ans += heapq.heappop(heap)-tmp
tmp += T[i]
ans += T[i]*len(heap)
print(ans, end=' ')
``` | output | 1 | 105,852 | 8 | 211,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,853 | 8 | 211,706 |
Tags: binary search, data structures
Correct Solution:
```
n = int(input())
import heapq as hq
heap = []
# total = 0
temp = 0
ans = [-1 for _ in range(n)]
volumes = [int(x) for x in input().split()]
temps = [int(x) for x in input().split()]
# prevtemp = 0
for i in range(n):
# hq.heappush(heap, volumes[i])
prevtemp = temp
temp += temps[i]
hq.heappush(heap, volumes[i] + prevtemp)
# total += 1
curr = 0
while len(heap) and heap[0] <= temp:
m = hq.heappop(heap)
curr += m - prevtemp
curr += (len(heap) * temps[i])
ans[i] = curr
print(' '.join([str(x) for x in ans]))
``` | output | 1 | 105,853 | 8 | 211,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,854 | 8 | 211,708 |
Tags: binary search, data structures
Correct Solution:
```
# import sys
# from io import StringIO
#
# sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read())
def bin_search_base(arr, val, base_index):
lo = base_index
hi = len(arr) - 1
while lo < hi:
if hi - lo == 1 and arr[lo] - arr[base_index] < val < arr[hi] - arr[base_index]:
return lo
if val >= arr[hi] - arr[base_index]:
return hi
c = (hi + lo) // 2
if val < arr[c] - arr[base_index]:
hi = c
elif val > arr[c] - arr[base_index]:
lo = c
else:
return c
return lo
n = int(input())
volumes = list(map(int, input().split()))
temps = list(map(int, input().split()))
temp_prefix = [0]
for i in range(n):
temp_prefix.append(temps[i] + temp_prefix[i])
gone_count = [0] * (n + 1)
remaining_count = [0] * n
gone_volume = [0] * (n + 1)
for i in range(n):
j = bin_search_base(temp_prefix, volumes[i], i)
gone_count[j] += 1
gone_volume[j] += volumes[i] - (temp_prefix[j] - temp_prefix[i])
for i in range(n):
remaining_count[i] = 1 + remaining_count[i-1] - gone_count[i]
for i in range(n):
gone_volume[i] += remaining_count[i] * temps[i]
print(' '.join(map(str, gone_volume[:n])))
``` | output | 1 | 105,854 | 8 | 211,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,855 | 8 | 211,710 |
Tags: binary search, data structures
Correct Solution:
```
import heapq
n = int(input())
V = list(map(int, input().split()))
T = list(map(int, input().split()))
a = []
ans = []
tmp = 0
for i in range(0, n):
heapq.heappush(a, tmp + V[i])
tmpAns = 0
while(len(a) and a[0] <= tmp + T[i]):
tmpAns += heapq.heappop(a) - tmp
tmpAns += len(a) * T[i]
ans.append(tmpAns)
tmp += T[i]
print(" ".join(map(str,ans)))
``` | output | 1 | 105,855 | 8 | 211,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,856 | 8 | 211,712 |
Tags: binary search, data structures
Correct Solution:
```
n = int(input())
vs = [int(x) for x in input().split()]
ts = [int(x) for x in input().split()]
from heapq import *
q = []
heapify(q)
sts = ts[:]
for i in range(1, n):
sts[i] += sts[i-1]
res = []
for i in range(n):
v = vs[i]
t = ts[i]
v += sts[i] - ts[i]
heappush(q, v)
minv = heappop(q)
count = 0
while minv <= sts[i]:
count += minv - sts[i] + ts[i]
if not q: break
minv = heappop(q)
else:
heappush(q, minv)
res.append(count + len(q) * t)
print(" ".join(map(str, res)))
``` | output | 1 | 105,856 | 8 | 211,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. | instruction | 0 | 105,857 | 8 | 211,714 |
Tags: binary search, data structures
Correct Solution:
```
from itertools import accumulate
from bisect import bisect
n = int(input())
vs = list(map(int, input().split()))
ts = list(map(int, input().split()))
fully_melt = [0] * n
result = [0] * n
dprint = lambda *args: None
#dprint = print
ts_accum = list(accumulate(ts))
dprint('ts_accum', ts_accum)
for i, v in enumerate(vs):
offset = ts_accum[i - 1] if i > 0 else 0
p = bisect(ts_accum, v + offset, lo=i)
dprint('i = ', i, ', p =', p, ', offset = ', offset)
if p < n:
fully_melt[p] += 1
result[p] -= ts_accum[p] - v - offset
dprint('fully_melt', fully_melt)
dprint('result', result)
multiplier = 1
for i, t in enumerate(ts):
dprint('i =', i, ', mult =', multiplier)
result[i] += t * multiplier
multiplier += 1 - fully_melt[i]
print(' '.join(str(r) for r in result))
``` | output | 1 | 105,857 | 8 | 211,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
import configparser
import math
import sys
input = sys.stdin.readline
def get(l, r, cumsum):
res = cumsum[r]
if l >= 1:
res -= cumsum[l-1]
return res
def can(l, r, cumsum, am):
return am >= get(l, r, cumsum)
def main():
n = int(input())
v = [int(x) for x in input().split(' ')]
t = [int(x) for x in input().split(' ')]
cumsum = [0 for i in range(n)]
cumsum[0] = t[0]
for i in range(1, n):
cumsum[i] = t[i] + cumsum[i-1]
ans = [0 for i in range(n)]
alive = [[] for i in range(n)]
for i in range(n):
pos = i-1
for j in range(25, -1, -1):
jump = 2**j
if pos+jump < n and can(i, pos+jump, cumsum, v[i]):
pos += jump
if pos == i - 1:
alive[i].append(v[i])
else:
ans[i] += 1
if pos + 1 < n:
ans[pos+1] -= 1
if pos != n-1 and v[i] > get(i, pos, cumsum):
alive[pos+1].append(v[i] - get(i, pos, cumsum))
for i in range(1, n):
ans[i] += ans[i-1]
res = [0 for i in range(n)]
for i in range(n):
res[i] = ans[i]*t[i]
for j in alive[i]:
res[i] += j
for i in res:
print(i, end=' ')
if __name__ == '__main__':
main()
``` | instruction | 0 | 105,858 | 8 | 211,716 |
Yes | output | 1 | 105,858 | 8 | 211,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
from sys import stdin
def binary_search(l, r, val):
global prefix
i, j = l, r
while i < j:
mid = (i + j) // 2
ptr = prefix[mid]
if ptr <= val:
i = mid + 1
else:
j = mid
return i
n = int(stdin.buffer.readline())
V = list(map(int, stdin.buffer.readline().split()))
T = list(map(int, stdin.buffer.readline().split()))
cnt = [0] * (n + 1)
res = [0] * (n + 1)
prefix = [0] * (n + 1)
for i in range(n):
if i == 0:
prefix[i] = T[i]
else:
prefix[i] = prefix[i - 1] + T[i]
for i in range(n):
id = None
if i == 0:
id = binary_search(i, n - 1, V[i])
else:
id = binary_search(i, n - 1, V[i] + prefix[i - 1])
if id == n - 1 and V[i] + prefix[i - 1] > prefix[id]:
id += 1
cnt[i] += 1
cnt[id] -= 1
if id == n:
continue
if i == 0:
res[id] += (T[id] - prefix[id] + V[i])
else:
res[id] += (T[id] - prefix[id] + V[i] + prefix[i - 1])
for i in range(n):
if i > 0:
cnt[i] += cnt[i - 1]
res[i] += cnt[i] * T[i]
for i in range(n):
if i == n - 1:
print(res[i])
else:
print(res[i], end = ' ')
``` | instruction | 0 | 105,859 | 8 | 211,718 |
Yes | output | 1 | 105,859 | 8 | 211,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
from math import *
from collections import *
def bs(x,i):
l = i
r = n-1
if(i != 0):
while(l <= r):
mid = (l+r)//2
if(mid == n-1):
return mid
if(pre[mid]-pre[i-1] > x and pre[mid-1]-pre[i-1] < x):
return mid
if(pre[mid]-pre[i-1] == x):
return mid
if(pre[mid]-pre[i-1] > x):
r = mid - 1
else:
l = mid + 1
else:
while(l <= r):
mid = (l+r)//2
if(mid == n-1):
return mid
if(pre[mid] > x and pre[mid-1] < x):
return mid
if(pre[mid] == x):
return mid
if(pre[mid] > x):
r = mid - 1
else:
l = mid + 1
return mid
n = int(input())
l = list(map(int,input().split()))
t = list(map(int,input().split()))
pre = [t[0]]
for i in range(1,n):
pre.append(pre[i-1] + t[i])
dis = [0 for i in range(n)]
val = [0 for i in range(n)]
for i in range(n):
dis[i] = bs(l[i],i)
#print(dis[i])
if dis[i] > 0:
if i > 0:
if(l[i] > pre[dis[i]] - pre[i-1]):
#print(i)
val[dis[i]] += t[dis[i]]
else:
val[dis[i]] += l[i] - pre[dis[i]-1] + pre[i-1]
else:
if(l[i] > pre[dis[i]]):
val[dis[i]] += t[dis[i]]
else:
val[dis[i]] += l[i] - pre[dis[i]-1]
else:
if(l[i] > pre[dis[i]]):
val[dis[i]] += t[dis[i]]
else:
val[dis[i]] += l[0]
ans = [0 for i in range(n)]
for i in range(n):
ans[i] += 1
ans[dis[i]] -= 1
for i in range(1,n):
ans[i] += ans[i-1]
for i in range(n):
ans[i] *= t[i]
ans[i] += val[i]
'''
print(pre)
print(dis)
print(val)
'''
for i in ans:
print(i,end = " ")
print()
``` | instruction | 0 | 105,860 | 8 | 211,720 |
Yes | output | 1 | 105,860 | 8 | 211,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
#!/usr/bin/env python3
from sys import stdin, stdout
from bisect import bisect
def rint():
return map(int, stdin.readline().split())
#lines = stdin.readlines()
N = int(input())
V = list(rint())
T = list(rint())
TT = [T[0]]
for i in range(1,N):
TT.append(TT[i-1] + T[i])
D = [ 0 for i in range(N)]
M = [ 0 for i in range(N)]
TT.append(0)
for i in range(0,N):
j = bisect(TT, V[i] + TT[i-1], i, N)
if j >= N:
continue
D[j] += 1
M[j] = M[j]+ V[i] - (TT[j-1] - TT[i-1])
for i in range(1,N):
D[i] += D[i-1]
ans = [ 0 for i in range(N)]
for i in range(N):
ans[i] = T[i]*(i+1 - D[i]) + M[i]
print(*ans)
``` | instruction | 0 | 105,861 | 8 | 211,722 |
Yes | output | 1 | 105,861 | 8 | 211,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
n = int(input())
vs = [int(x) for x in input().split()]
ts = [int(x) for x in input().split()]
from heapq import *
q = []
heapify(q)
sts = ts[:]
for i in range(1, n):
sts[i] += sts[i-1]
res = []
for i in range(n):
v = vs[i]
t = ts[i]
if i: v += sts[i-1]
heappush(q, v)
minv = heappop(q)
if minv > sts[i]:
heappush(q, minv)
res.append(len(q) * t)
else:
count = 0
while minv <= sts[i]:
count += minv - sts[i-1]
if not q: break
minv = heappop(q)
else:
heappush(q, minv)
res.append(count + len(q) * t)
print(" ".join(map(str, res)))
``` | instruction | 0 | 105,862 | 8 | 211,724 |
No | output | 1 | 105,862 | 8 | 211,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
import heapq
heap = []
n = int(input())
V = list(map(int, input().split()))
T = list(map(int, input().split()))
tmp = 0
for i in range(n):
ans = 0
heapq.heappush(heap, V[i])
while len(heap) and heap[0]<=T[i]:
ans += heapq.heappop(heap)
tmp += T[i]
ans += T[i]*len(heap)
print(ans, end=' ')
``` | instruction | 0 | 105,863 | 8 | 211,726 |
No | output | 1 | 105,863 | 8 | 211,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
def binary_search(a, l, r, num):
mid = (l+r)//2
# print("l==" + str(l) + ", r==" + str(r) + ", mid==" + str(mid))
if(mid == num):
return mid+1
if(l > r):
return l
if(a[mid] < num):
return binary_search(a, l+1, r, num)
else:
return binary_search(a, l, r-1, num)
n = int(input())
V = list(map(int, input().split()))
T = list(map(int, input().split()))
a = []
ans = []
for i in range(0, n):
index = binary_search(a, 0, len(a)-1, V[i])
# print("index==" + str(index))
a.insert(index, V[i])
# print(a)
index0 = binary_search(a, 0, len(a)-1, T[i])
# print("index0==" + str(index0))
# print("sum==" + str(sum(a[:index0])))
ans.append(sum(a[:index0]) + (len(a) - index0)*T[i])
del a[:index0]
for j in range(0, len(a)):
a[j] -= T[i]
print(" ".join(map(str,ans)))
``` | instruction | 0 | 105,864 | 8 | 211,728 |
No | output | 1 | 105,864 | 8 | 211,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 β€ N β€ 105) β the number of days.
The second line contains N integers V1, V2, ..., VN (0 β€ Vi β€ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, ..., TN (0 β€ Ti β€ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
Input
3
10 10 5
5 7 2
Output
5 12 4
Input
5
30 25 20 15 10
9 10 12 4 13
Output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Submitted Solution:
```
import configparser
import math
import sys
input = sys.stdin.readline
def get(l, r, cumsum):
res = cumsum[r]
if l >= 1:
res -= cumsum[l-1]
return res
def can(l, r, cumsum, am):
return am >= get(l, r, cumsum)
def main():
n = int(input())
v = [int(x) for x in input().split(' ')]
t = [int(x) for x in input().split(' ')]
cumsum = [0 for i in range(n)]
cumsum[0] = t[0]
for i in range(1, n):
cumsum[i] = t[i] + cumsum[i-1]
ans = [0 for i in range(n)]
alive = [[] for i in range(n)]
for i in range(n):
pos = i-1
for j in range(6, -1, -1):
jump = 2**j
if pos+jump < n and can(i, pos+jump, cumsum, v[i]):
pos += jump
if pos == i - 1:
alive[i].append(v[i])
else:
ans[i] += 1
if pos + 1 < n:
ans[pos+1] -= 1
if pos != n-1 and v[i] > get(i, pos, cumsum):
alive[pos+1].append(v[i] - get(i, pos, cumsum))
for i in range(1, n):
ans[i] += ans[i-1]
res = [0 for i in range(n)]
for i in range(n):
res[i] = ans[i]*t[i]
for j in alive[i]:
res[i] += j
for i in res:
print(i, end=' ')
if __name__ == '__main__':
main()
``` | instruction | 0 | 105,865 | 8 | 211,730 |
No | output | 1 | 105,865 | 8 | 211,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
for i in range(n + 1):
if i < n and k < m:
k += a[i] - 1
else:
break;
if k >= m:
print(i)
else:
print(-1)
``` | instruction | 0 | 106,452 | 8 | 212,904 |
Yes | output | 1 | 106,452 | 8 | 212,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
i, res = 0, 0
arr = sorted(arr, reverse=True)
while i < n and k < m:
k += arr[i] - 1
res += 1
i += 1
print(-1 if k < m else res)
``` | instruction | 0 | 106,453 | 8 | 212,906 |
Yes | output | 1 | 106,453 | 8 | 212,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n,m,k = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x=x[::-1]
if m<=k:
print(0)
else:
d=0
f=1
for i in x:
k+=i-1
d+=1
if m<=k:
print(d)
f=0
break
if f :
print(-1)
``` | instruction | 0 | 106,454 | 8 | 212,908 |
Yes | output | 1 | 106,454 | 8 | 212,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split());
a = list(map(int, input().split()));
a.sort(reverse = True);
if sum(a)+k-n < m:
print(-1);
elif k >= m:
print(0);
else:
for i in range (1, n+1):
if sum(a[:i])+k-i >= m:
print(i)
break;
``` | instruction | 0 | 106,455 | 8 | 212,910 |
Yes | output | 1 | 106,455 | 8 | 212,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n,m,k = map(int ,input().split())
t = list(map(int,input().split()))
t.sort()
g=[1]*(k)
k-=1
f=0
l,h=0,0
j=n-1
while True:
if k>=0 and j>=0:
g[k]+=t[j]-1
j-=1
k-=1
l+=1
if sum(g)>=m:
print(l)
h+=1
break
if k<0 and j>=0:
k=len(g)-1
if k<0 and j<0:
if sum(g)<m:
break
else:
print(l)
break
if h==0:
print(-1)
``` | instruction | 0 | 106,456 | 8 | 212,912 |
No | output | 1 | 106,456 | 8 | 212,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
# cook your dish here
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
#print(a)
c=0
devices = k
i=0
while(devices<m and i<n):
c+=1
devices+=a[i]
if(devices<n):
print(-1)
else:
print(c)
``` | instruction | 0 | 106,457 | 8 | 212,914 |
No | output | 1 | 106,457 | 8 | 212,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
for i in range(n):
if k < m:
k += a.pop(0)
else:
break;
if k >= m:
print(i)
else:
print(-1)
``` | instruction | 0 | 106,458 | 8 | 212,916 |
No | output | 1 | 106,458 | 8 | 212,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.
Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity.
What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 50) β the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 50) β number ai stands for the number of sockets on the i-th supply-line filter.
Output
Print a single number β the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
Examples
Input
3 5 3
3 1 2
Output
1
Input
4 7 2
3 3 2 4
Output
2
Input
5 5 1
1 3 1 2 1
Output
-1
Note
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter.
Submitted Solution:
```
n, m, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
c = 0
while k < m and c < n:
k += a[c] - 1
c += 1
if c > 0 and k >= m:
print(c)
else:
print(-1)
``` | instruction | 0 | 106,459 | 8 | 212,918 |
No | output | 1 | 106,459 | 8 | 212,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6 | instruction | 0 | 106,476 | 8 | 212,952 |
Tags: brute force
Correct Solution:
```
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
a=0
for i in range(n-1):
for j in range(i+1,n):
if(l[j]-l[i]<=m):
a+=1
else:
break
print(a*2)
``` | output | 1 | 106,476 | 8 | 212,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6 | instruction | 0 | 106,477 | 8 | 212,954 |
Tags: brute force
Correct Solution:
```
n, d = map(int, input().split())
c = list(map(int, input().split()))
counter = 0
for i in range(len(c)):
for j in range(i+1, len(c)):
if abs(c[i] - c[j]) <= d:
counter += 2
print(counter)
``` | output | 1 | 106,477 | 8 | 212,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6 | instruction | 0 | 106,478 | 8 | 212,956 |
Tags: brute force
Correct Solution:
```
x,y=[ int(a) for a in input().split()]
l=[int(b) for b in input().split()]
count=0
k=len(l)-1
for i in range(len(l)-1):
for j in range(i+1,len(l)):
if abs(l[j]-l[i])<=y:
count=count+1
print(count*2)
``` | output | 1 | 106,478 | 8 | 212,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6 | instruction | 0 | 106,479 | 8 | 212,958 |
Tags: brute force
Correct Solution:
```
import sys
def solution(n, d, a_arr):
count = 0
for i in range(len(a_arr)):
for j in range(len(a_arr)):
if i == j:
continue
diff = abs(a_arr[i]-a_arr[j])
#print(diff, d, count)
if diff <= d:
count += 1
return count
if __name__ == '__main__':
n = sys.stdin.readline()
while n:
n_in, d = n.split() # array length
a_arr = [int(i) for i in sys.stdin.readline().split()] # input array
print(solution(int(n_in), int(d), a_arr))
n = sys.stdin.readline()
``` | output | 1 | 106,479 | 8 | 212,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6 | instruction | 0 | 106,480 | 8 | 212,960 |
Tags: brute force
Correct Solution:
```
(n, d) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
result = 0
for i in range(len(a) - 1):
for j in range(i+1, len(a)):
if abs(a[i] - a[j]) <= d:
result += 2
print(result)
``` | output | 1 | 106,480 | 8 | 212,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1, 2) and (2, 1) should be regarded as different.
Input
The first line contains two integers n and d (1 β€ n β€ 1000, 1 β€ d β€ 109) β amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output
Output one number β amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
Examples
Input
5 10
10 20 50 60 65
Output
6
Input
5 1
55 30 29 31 55
Output
6 | instruction | 0 | 106,481 | 8 | 212,962 |
Tags: brute force
Correct Solution:
```
n, d = [int(s) for s in input().split(' ')]
a = [int(s) for s in input().split(' ')]
a.sort()
pairs = 0
for i in range(n - 1):
for j in range(i + 1, n):
if a[j] - a[i] <= d:
pairs += 2
else:
break
print(pairs)
``` | output | 1 | 106,481 | 8 | 212,963 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.