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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
Submitted Solution:
```
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
for i in a:
print(i,end=' ')
``` | instruction | 0 | 61,026 | 8 | 122,052 |
Yes | output | 1 | 61,026 | 8 | 122,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
Submitted Solution:
```
_input = input('')
# _list = ' '.join(sorted(input(''))).strip()
_list = input().strip().split()
_list.sort()
print(' '.join(_list))
``` | instruction | 0 | 61,027 | 8 | 122,054 |
No | output | 1 | 61,027 | 8 | 122,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
<image>
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!
Input
The first line of input contains an integer n (1 β€ n β€ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 β€ ai β€ 100) denotes the number of cubes in the i-th column.
Output
Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.
Examples
Input
4
3 2 1 2
Output
1 2 2 3
Input
3
2 3 8
Output
2 3 8
Note
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns.
Submitted Solution:
```
n = int(input())
a = []
inp = input().split()
for i in range(n):
a.append(int(inp[i]))
for j in range(n):
for i in range(n-1):
if a[i+1] < a[i]:
d = a[i] - a[i+1]
a[i] -= d
a[i+1] += d
print(a)
``` | instruction | 0 | 61,030 | 8 | 122,060 |
No | output | 1 | 61,030 | 8 | 122,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,163 | 8 | 122,326 |
Tags: binary search, greedy
Correct Solution:
```
hobs, pillows, frodo = input().split()
hobs, pillows, frodo = int(hobs), int(pillows), int(frodo)
turn = 0
left = frodo
right = frodo
pilCount = 1
pillows-=hobs
while True:
if left < 1 and right > hobs:
pilCount+=pillows//hobs
break
elif left < 1:
pillows-=(right)
elif right > hobs:
pillows-=(hobs-left+1)
else:
pillows-=(turn*2+1)
if pillows < 0:
break
left-=1
right+=1
pilCount+=1
turn+=1
print(pilCount)
``` | output | 1 | 61,163 | 8 | 122,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,164 | 8 | 122,328 |
Tags: binary search, greedy
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 3 10:37:54 2019
@author: slappy
"""
def _sum_n(n):
return int((n * (n + 1)) // 2)
def _sum(p, k):
return _sum_n(p) - (_sum_n(p - k) if p > k else p - k)
def _solve():
n, m, k = map(int, input().split())
low, high = 1, 2e9
while low <= high:
mid = int((low + high) // 2)
sum = int(_sum(mid, k) + _sum(mid - 1, n - k))
#print (mid, ' ', sum)
if sum <= m:
ans = mid
low = mid + 1
else:
high = mid - 1
return ans
print (int(_solve()))
``` | output | 1 | 61,164 | 8 | 122,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,165 | 8 | 122,330 |
Tags: binary search, greedy
Correct Solution:
```
n, m, k = map(int, input().split())
def quiero(s):
ne = s + (s-1)*s
# print(ne)
if s > k:
d = s-k
ne -= d*(d+1)//2
# print(ne)
if s+k-1>n:
d = s+k-n-1
ne -= d*(d+1)//2
# print(ne)
return ne
lo, hi = 0, m
while hi > lo:
mid = (hi+lo+1)//2
if n + quiero(mid) <= m:
lo = mid
else:
hi = mid - 1
print(lo+1)
``` | output | 1 | 61,165 | 8 | 122,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,166 | 8 | 122,332 |
Tags: binary search, greedy
Correct Solution:
```
def main():
n, hi, k = map(int, input().split())
m, l, lo = (hi - n) * 2, n - k + 1, 0
while lo < hi - 1:
mid = (lo + hi) // 2
x = mid * mid * 2
if mid > k:
x -= (mid - k) * (mid - k + 1)
if mid > l:
x -= (mid - l) * (mid - l + 1)
if x > m:
hi = mid
else:
lo = mid
print(lo + 1)
if __name__ == '__main__':
main()
``` | output | 1 | 61,166 | 8 | 122,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,167 | 8 | 122,334 |
Tags: binary search, greedy
Correct Solution:
```
hob, pil, fro = map(int, input().split())
pil -= hob
ans = 1
rad = 0
x, y = fro-1, hob-fro
while pil > 0:
if rad >= max(x,y):
ans += pil//hob
break
pil -= min(rad, x)
pil -= min(rad, y)
if pil < 1:
break
pil -= 1
ans += 1
rad += 1
print(ans)
``` | output | 1 | 61,167 | 8 | 122,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,168 | 8 | 122,336 |
Tags: binary search, greedy
Correct Solution:
```
def v(length, start):
W = start * (start + 1) // 2
t = max(0, start - length)
T = t * (t + 1) // 2
return W - T + max(0, length - start)
def check(p):
return p + v(k - 1, p - 1) + v(n - k, p - 1) <= m
n, m, k = map(int, input().split())
l = 0
r = 10 ** 100
while r - l > 1:
mid = (l + r) // 2
if not check(mid):
r = mid
else:
l = mid
print(l)
``` | output | 1 | 61,168 | 8 | 122,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,169 | 8 | 122,338 |
Tags: binary search, greedy
Correct Solution:
```
q,w,e=map(int,input().split())
w-=q
z=e-1
x=q-e
z,x=min(z,x),max(z,x)
ans=1
t=1
while (w-t)>=0:
w-=t
ans+=1
if z==x==0:
ans+=w//t
break
if z>0:
z-=1
t+=1
if x>0:
x-=1
t+=1
print(ans)
``` | output | 1 | 61,169 | 8 | 122,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | instruction | 0 | 61,170 | 8 | 122,340 |
Tags: binary search, greedy
Correct Solution:
```
import sys
import math
n, m, k = map(int, input().split())
ans = 1
m -= n
l = min(k - 1, n - k)
step = 1
for i in range(l):
if m - step < 0:
print(ans)
sys.exit(0)
m -= step
step += 2
ans += 1
while step < n:
if m - step < 0:
print(ans)
sys.exit(0)
m -= step
step += 1
ans += 1
ans += m // n
print(ans)
``` | output | 1 | 61,170 | 8 | 122,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
n, m , k = [int(i) for i in input().split()]
def get_min_pillow(bed,x):
res = x * (x + 1) / 2
if bed >= x :
res += bed - x
else:
temp = x - bed
res -= temp * (temp + 1)/2
return res
def get_min(s,x):
return x * (x + 1) / 2 + (s - x) if s >= x else s * (x + x - s + 1) / 2
def check(x):
return (get_min(k,x) + get_min(n-k+1,x) - x) <= m
l = (m + n - 1) // n
r = m + 1
while r - l > 1:
mid = (l + r) >> 1
if check(mid):
l = mid
else:
r = mid
print(l)
``` | instruction | 0 | 61,171 | 8 | 122,342 |
Yes | output | 1 | 61,171 | 8 | 122,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
n, m, k = map(int, input().split())
f = lambda k, s: (2 * s - k + 1) * k - s if k < s else (s - 2) * s + 2 * k
s, m = m // n + 1, 2 * m + 1
while f(k, s) + f(n - k + 1, s) < m: s += 1
print(s - 1)
# Made By Mostafa_Khaled
``` | instruction | 0 | 61,172 | 8 | 122,344 |
Yes | output | 1 | 61,172 | 8 | 122,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
def bin_search(l, r, func):
while l < r:
c = (l + r) // 2
val = func(c)
if l + 1 == r:
if func(r):
return r
if func(l):
return l
if val:
l = c
else:
r = c - 1
# print('l: %s, r: %s' % (l, r))
if l == r:
return l
else:
return 1
def solve(n, m, k):
hr, hl = k-1, n-k
s_one_n = lambda n: n * (1.0 + n) / 2.0
def s_n_m(n, m):
return (m-n+1) * (n+m) / 2.0
def snm(n, m):
return s_one_n(max(n,m)) - s_one_n(min(n,m)-1)
def calc_side(ft, hs):
if hs == 0:
return 0
return s_n_m(max(1, ft - hs), ft - 1) + max(0, hs - ft + 1)
f = lambda x: calc_side(x, hl) + calc_side(x, hr) + x <= m
print(bin_search(1, m*3, f))
n,m,k = map(int, input().split(' '))
solve(n,m,k)
``` | instruction | 0 | 61,173 | 8 | 122,346 |
Yes | output | 1 | 61,173 | 8 | 122,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
import math
def c(k,n):
return (k-1)*(k-1)+(n-k*2+1)*(n-k*2)/2+(k*2-1)*(n-k*2+1)
n,m,k=list(map(int,input().split()))
m=m-n
if k>n/2:
k=n-k+1
if k*k>=m:
print(int(m**0.5)+1)
exit()
elif c(k,n)>=m:
m=m-(k-1)*(k-1)
#for i in range(n+5):
# if i*((i-1)/2+k*2)>m:
# print(i+k)
# exit()
for i in range(n+5):
if i+k*2-1>m:
print(i+k)
exit()
m=m-i-k*2+1
else:
m=m-c(k,n)
print(int(m//n+n-k+1))
``` | instruction | 0 | 61,174 | 8 | 122,348 |
Yes | output | 1 | 61,174 | 8 | 122,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
n, p, f = map(int, input().split())
f -= 1
p -= n
if p == 0:
print(1)
exit()
def check_p(p, f, n):
x = p - (n - f) - 1
y = p - f
return p * p - (x * (x + 1) // 2) * (x > 0) - (y * (y + 1) // 2) * (y > 0)
high = p - 1
low = 0
while True:
curr = (high + low) // 2
x = check_p(curr, f, n)
if x > p:
high = curr - 1
elif x == p or (x < p < check_p(curr + 1, f, n)) or curr == p - 1:
print(curr + 1)
break
else:
low = curr + 1
``` | instruction | 0 | 61,175 | 8 | 122,350 |
No | output | 1 | 61,175 | 8 | 122,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
from sys import stdin, stdout
n, m, k = map(int, stdin.readline().split())
m = m - n + 1
ans = min(2, m)
m -= min(2, m)
if k == 1 or k == n:
cnt = min(n, 2)
while m - cnt >= 0:
ans += 1
m -= cnt
cnt += 1
cnt = min(cnt, n)
if cnt == n:
break
ans += m // cnt
else:
cnt = min(n, 3)
while m - cnt >= 0:
ans += 1
m -= cnt
cnt += 2
cnt = min(cnt, n)
if cnt == n:
break
ans += m // cnt
stdout.write(str(ans))
``` | instruction | 0 | 61,176 | 8 | 122,352 |
No | output | 1 | 61,176 | 8 | 122,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
def just_sum(n):
return (n * (n + 1)) // 2
def get_sum(a, b):
return just_sum(b) - just_sum(a - 1)
def check(middle):
left = k - 1
right = n - k
if left < m:
left_sum = get_sum(middle - left, middle - 1)
else:
left_sum = just_sum(middle - 1) + (left - (middle - 1))
if right < m:
right_sum = get_sum(middle - right, middle - 1)
else:
right_sum = just_sum(middle - 1) + (right - (middle - 1))
return left_sum + right_sum + middle <= m
n, m, k = map(int, input().split())
l = 1
r = m + 1
while l < r - 1:
middle = (l + r) // 2
if check(middle):
l = middle
else:
r = middle
print(l)
``` | instruction | 0 | 61,177 | 8 | 122,354 |
No | output | 1 | 61,177 | 8 | 122,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n β€ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
Input
The only line contain three integers n, m and k (1 β€ n β€ m β€ 109, 1 β€ k β€ n) β the number of hobbits, the number of pillows and the number of Frodo's bed.
Output
Print single integer β the maximum number of pillows Frodo can have so that no one is hurt.
Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
Note
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.
Submitted Solution:
```
n, m, k = map(int, input().split())
done = 0
for A in range(m // n,m+1):
up = A
if (k-1) >= (A-1):
up = up + A * (A-1) / 2
up = up + k - A
else:
s = A - k + 1
up = up + (s + (A - 1)) * (A - s) / 2
kk = n - k
if (kk-1) >= (A-1):
up = up + A * (A-1) / 2
up = up + kk - A
else:
s = A - kk
up = up + (s + (A - 1)) * (A - s) / 2
if up > m:
done = 1
print(A-1)
break
if done == 0:
print(m)
``` | instruction | 0 | 61,178 | 8 | 122,356 |
No | output | 1 | 61,178 | 8 | 122,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,211 | 8 | 122,422 |
Tags: implementation
Correct Solution:
```
for _ in range(int(input())):
n, k = map(int, input().split())
x = list(sorted(map(int, input().split())))
m = max([(x[i] - x[i - 1]) // 2 + 1 for i in range(1, len(x))] + [x[0], n - x[-1] + 1])
print(m)
``` | output | 1 | 61,211 | 8 | 122,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,212 | 8 | 122,424 |
Tags: implementation
Correct Solution:
```
# n=int(input())
# arr=list(map(int,input().strip().split(' ')))
# arr=input().strip().split(' ')
import math
t=int(input())
a=[]
for _ in range(t):
n,k = list(map(int, input().strip().split(' ')))
arr = list(map(int, input().strip().split(' ')))
res=arr[0]-1
for i in range(1,k):
if math.ceil((arr[i]-arr[i-1])/2)>res:
res=math.floor((arr[i]-arr[i-1])/2)
if n-arr[-1]>res:
res=n-arr[-1]
print(res+1)
# a.append(res+1)
# for i in a:
# print(i)
``` | output | 1 | 61,212 | 8 | 122,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,213 | 8 | 122,426 |
Tags: implementation
Correct Solution:
```
t = int(input())
for tc in range(t):
n,k=map(int, input().split())
tap = list(map(int, input().split()))
sol=0
for i in range(1, n+1):
d=1000000
for j in tap:
d=min(d, abs(j-i)+1)
sol=max(sol, d)
print(sol)
``` | output | 1 | 61,213 | 8 | 122,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,214 | 8 | 122,428 |
Tags: implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
taps = [int(x) for x in input().split()]
result = 0
for i in range(1, n + 1):
best = n + 1
for x in taps:
best = min([best, abs(x - i)])
result = max([result, best])
print(result + 1)
``` | output | 1 | 61,214 | 8 | 122,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,215 | 8 | 122,430 |
Tags: implementation
Correct Solution:
```
n = int(input())
def time(str1,str2):
x = str1[0]
m = [1]*x
l = 0
while(1):
for k in range(len(str2)):
if str2[k] - l - 1 >= 0:
m[str2[k] - l -1] = 0
if str2[k] + l - 1 <= x-1 :
m[str2[k] + l -1] = 0
l+=1
if sum(m) == 0:
return(l)
break
for i in range(n):
arr =list(map(int,input().split(' ')))
arr1 =list(map(int,input().split(' ')))
result = time(arr,arr1)
print(result)
``` | output | 1 | 61,215 | 8 | 122,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,216 | 8 | 122,432 |
Tags: implementation
Correct Solution:
```
# int(input())
# [int(i) for i in input().split()]
t = int(input())
for tt in range(t):
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
max_dist = 0
curr = 0
for i in range(1,n+1):
x = i
if curr != k-1 and abs(x-a[curr]) > abs (x - a[curr + 1]):
curr += 1
if abs(x - a[curr]) > max_dist:
max_dist = abs(x - a[curr])
print(max_dist+1)
``` | output | 1 | 61,216 | 8 | 122,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,217 | 8 | 122,434 |
Tags: implementation
Correct Solution:
```
for _ in range(int(input())):
n, k = map(int, input().split())
x = list(map(int, input().split()))
time = 1
while True:
used = [False] * n
for xx in x:
for i in range(time):
used[max(0, xx - i - 1)] = True
used[min(n - 1, xx + i - 1)] = True
if used.count(False) == 0:
break
time += 1
print(time)
``` | output | 1 | 61,217 | 8 | 122,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
<image> The garden from test 1. White colour denotes a garden bed without a tap, red colour β a garden bed with a tap. <image> The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour β a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t β the number of test cases to solve (1 β€ t β€ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 β€ n β€ 200, 1 β€ k β€ n) β the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 β€ xi β€ n) β the location of i-th water tap. It is guaranteed that for each <image> condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer β the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | instruction | 0 | 61,218 | 8 | 122,436 |
Tags: implementation
Correct Solution:
```
for i in range(int(input())):
n,k=map(int,map(int,input().split()))
a=list(map(int,input().split()))
x=0
m=max(a[0],n-a[-1]+1)
for i in range(k-1):
if (a[i+1]-a[i]+2)//2>m:
m=(a[i+1]-a[i]+2)//2
print(m)
``` | output | 1 | 61,218 | 8 | 122,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,504 | 8 | 123,008 |
Tags: implementation
Correct Solution:
```
w1,h1=map(int,input().split())
w2,h2=map(int,input().split())
w3,h3=map(int,input().split())
for i in range (h1,0,-1):
w1+=i
if(i==h2):
w1-=w2
if(i==h3):
w1-=w3
if(w1<0):
w1=0
print(w1)
``` | output | 1 | 61,504 | 8 | 123,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,505 | 8 | 123,010 |
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
def rli():
return list(map(int, input().split()))
def main():
w, h = rli()
stones = []
for i in range(2):
u, d = rli()
stones.append((d, u))
stones.sort()
stones.reverse()
stones.append((float('inf'), 0))
now = 0
si = 0
while h:
w += h
if h == stones[si][0]:
w -= stones[si][1]
si += 1
if w < 0:
w = 0
now += 1
h -= 1
print(w)
if __name__ == '__main__':
main()
``` | output | 1 | 61,505 | 8 | 123,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,506 | 8 | 123,012 |
Tags: implementation
Correct Solution:
```
w,h = map(int,input().split())
u1,d1 = map(int,input().split())
u2,d2 = map(int,input().split())
for i in range(h,0,-1):
w+=i
if i==d1:
w-=u1
w = max(0,w)
if i==d2:
w-=u2
w = max(0,w)
print(w)
``` | output | 1 | 61,506 | 8 | 123,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,507 | 8 | 123,014 |
Tags: implementation
Correct Solution:
```
# Entrada
SNOW = [ int(x) for x in input().split()]
S1 = [ int(x) for x in input().split()]
S2 = [ int(x) for x in input().split()]
for h in range(SNOW[1]):
i = SNOW[1] - h
SNOW[0] += i
if i == S1[1]:
SNOW[0] -= S1[0]
if i == S2[1]:
SNOW[0] -= S2[0]
if SNOW[0] <= 0:
SNOW[0] = 0
print(SNOW[0])
``` | output | 1 | 61,507 | 8 | 123,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,508 | 8 | 123,016 |
Tags: implementation
Correct Solution:
```
w , h = map(int,input().split())
w1 , h1 = map(int,input().split())
w2 , h2 = map(int,input().split())
res = w
for i in range(h,-1,-1):
res += i
if i==h1:
res-=w1
elif i==h2:
res-=w2
if res<0:
res = 0
print(res)
``` | output | 1 | 61,508 | 8 | 123,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,509 | 8 | 123,018 |
Tags: implementation
Correct Solution:
```
w, h = map(int, input().split())
w1, h1 = map(int, input().split())
w2, h2 = map(int, input().split())
if h1>h2:
w1,w2=w2,w1
h1,h2=h2,h1
ans=int(w+(h-h2+1)*(h2+h)//2-w2)
if ans<0:ans=0
ans+=int((h2-h1)*(h2-1+h1)//2-w1)
if ans<0:
ans=0
ans+=int(h1*(h1-1)//2)
if ans<0:
print(0)
else:
print(ans)
``` | output | 1 | 61,509 | 8 | 123,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,510 | 8 | 123,020 |
Tags: implementation
Correct Solution:
```
w, h = map(int, input().split())
u1, d1 = map(int, input().split())
u2, d2 = map(int, input().split())
while h != 0:
w += h
if d1 == h:
w -= u1
elif d2 == h:
w -= u2
if w < 0:
w = 0
h -= 1
print(w)
``` | output | 1 | 61,510 | 8 | 123,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8. | instruction | 0 | 61,511 | 8 | 123,022 |
Tags: implementation
Correct Solution:
```
kom = input().split()
k1 = input().split()
k2 = input().split()
w = int(kom[0])
h = int(kom[1])
w1 = int(k1[0])
h1 = int(k1[1])
w2 = int(k2[0])
h2 = int(k2[1])
i = h
while True:
if i != h1 and i != h2:
w += i
i -= 1
elif i == h1:
w += i
w = w - w1
i -= 1
elif i == h2:
w += i
w = w - w2
i -= 1
if w <= 0:
w = 0
if i == 0:
print(w)
break
``` | output | 1 | 61,511 | 8 | 123,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
# problem http://codeforces.com/problemset/problem/1099/A
def calculate(w, h, u1, d1, u2, d2):
sq = lambda x: int(x * (x + 1) / 2)
before_1_stone = w + sq(h) - sq(d1 - 1)
before_2_stone = max(before_1_stone - u1, 0) + sq(d1 - 1) - sq(d2 - 1)
finish = max(before_2_stone - u2, 0) + sq(d2 - 1)
return finish
if __name__ == '__main__':
w, h = map(int, input().split())
u1, d1 = map(int, input().split())
u2, d2 = map(int, input().split())
if d1 < d2:
d1, d2 = d2, d1
u1, u2 = u2, u1
print(calculate(w, h, u1, d1, u2, d2))
``` | instruction | 0 | 61,512 | 8 | 123,024 |
Yes | output | 1 | 61,512 | 8 | 123,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
w,h = map(int,input().split())
u1,d1 = map(int,input().split())
u2,d2 = map(int,input().split())
while h != 0:
w += h
if h == d1: w -= u1
if h == d2: w -= u2
if w < 0: w = 0
h -= 1
print(w)
``` | instruction | 0 | 61,513 | 8 | 123,026 |
Yes | output | 1 | 61,513 | 8 | 123,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
x1,x2,x3=input().split(), input().split(), input().split()
w,h= int(x1[0]), int(x1[1])
w1,h1,w2,h2= int(x2[0]), int(x2[1]), int(x3[0]), int(x3[1])
while not h==0:
w= w+h
if h==h1 or h==h2:
if h==h1:
w=w-w1
else:
w=w-w2
if w<0:
w=0
h= h-1
print(w)
``` | instruction | 0 | 61,514 | 8 | 123,028 |
Yes | output | 1 | 61,514 | 8 | 123,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
s1 = input()
s1 = s1.split()
w = int(s1[0])
h = int(s1[1])
s2 = input()
s2 = s2.split()
u1 = int(s2[0])
d1 = int(s2[1])
s3 = input()
s3 = s3.split()
u2 = int(s3[0])
d2 = int(s3[1])
while h != 0:
if h == d1:
w = w - u1
elif h == d2:
w = w - u2
w += h
if w < 0:
w = 0
h -= 1
print(w)
``` | instruction | 0 | 61,515 | 8 | 123,030 |
Yes | output | 1 | 61,515 | 8 | 123,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
w,h=map(int,input().split())
s1,h1=map(int,input().split())
s2,h2=map(int,input().split())
w+=h
while h!=0:
if h==h1:
h-=1
w+=h
w-=s1
elif h==h2:
h-=1
w+=h
w-=s2
else:
h-=1
w+=h
print(w)
``` | instruction | 0 | 61,516 | 8 | 123,032 |
No | output | 1 | 61,516 | 8 | 123,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
w,h=map(int,input().split())
u1,h1=map(int,input().split())
u2,h2=map(int,input().split())
Answer=w+h
while h!=0:
if h==h1:
Answer-=u1
h-=1
elif h==h2:
Answer-=u2
h-=1
else:
h-=1
Answer+=h
print(min((Answer+1),0))
``` | instruction | 0 | 61,517 | 8 | 123,034 |
No | output | 1 | 61,517 | 8 | 123,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
def main(s, s1, s2):
index = s[1]
w = s[0]
while index >= 0:
w = w + index
if index == s1[1]:
w = w - s1[0]
elif index == s2[1]:
w = w - s2[0]
index = index - 1
if w < 0:
return 0
return w
if __name__ == '__main__':
s = list(map(int, input().rstrip().split()))
s1 = list(map(int, input().rstrip().split()))
s2 = list(map(int, input().rstrip().split()))
res = main(s, s1, s2)
print(res)
``` | instruction | 0 | 61,518 | 8 | 123,036 |
No | output | 1 | 61,518 | 8 | 123,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain.
Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i, where i β is the current height of snowball, then snowball hits the stone (if it's present at the current height), then snowball moves one meter down. If the snowball reaches height zero, it stops.
There are exactly two stones on the mountain. First stone has weight u_1 and is located at height d_1, the second one β u_2 and d_2 respectively. When the snowball hits either of two stones, it loses weight equal to the weight of that stone. If after this snowball has negative weight, then its weight becomes zero, but the snowball continues moving as before.
<image>
Find the weight of the snowball when it stops moving, that is, it reaches height 0.
Input
First line contains two integers w and h β initial weight and height of the snowball (0 β€ w β€ 100; 1 β€ h β€ 100).
Second line contains two integers u_1 and d_1 β weight and height of the first stone (0 β€ u_1 β€ 100; 1 β€ d_1 β€ h).
Third line contains two integers u_2 and d_2 β weight and heigth of the second stone (0 β€ u_2 β€ 100; 1 β€ d_2 β€ h; d_1 β d_2). Notice that stones always have different heights.
Output
Output a single integer β final weight of the snowball after it reaches height 0.
Examples
Input
4 3
1 1
1 2
Output
8
Input
4 3
9 2
0 1
Output
1
Note
In the first example, initially a snowball of weight 4 is located at a height of 3, there are two stones of weight 1, at a height of 1 and 2, respectively. The following events occur sequentially:
* The weight of the snowball increases by 3 (current height), becomes equal to 7.
* The snowball moves one meter down, the current height becomes equal to 2.
* The weight of the snowball increases by 2 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 1.
* The weight of the snowball increases by 1 (current height), becomes equal to 9.
* The snowball hits the stone, its weight decreases by 1 (the weight of the stone), becomes equal to 8.
* The snowball moves one meter down, the current height becomes equal to 0.
Thus, at the end the weight of the snowball is equal to 8.
Submitted Solution:
```
w,h=map(int,input().split())
u1,d1=map(int,input().split())
u2,d2=map(int,input().split())
c=0
i=h
while(i>0):
w+=i
if(i==d1):
w-=u1
c+=1
if(i==d2):
w-=u2
c+=1
if(c==2):
break
i-=1
print(w+(i*(i-1))//2)
``` | instruction | 0 | 61,519 | 8 | 123,038 |
No | output | 1 | 61,519 | 8 | 123,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,554 | 8 | 123,108 |
Tags: dp
Correct Solution:
```
import sys
input=sys.stdin.buffer.readline
for _ in range(int(input())):
n=int(input())
arr=[]
for i in range(n):
a,b=map(int,input().split())
arr.append([a,b])
dp=[[999999999999999999999999999 for i in range(3)] for j in range(n)]
dp[0][0]=0
dp[0][1]=arr[0][1]
dp[0][2]=arr[0][1]*2
dpp=[[0 for i in range(3)] for j in range(n)]
for i in range(n):
for j in range(3):
dpp[i][j]=arr[i][0]+j
j=0
for i in range(1,n):
for j in range(3):
for k in range(3):
if(dpp[i-1][k]-dpp[i][j]==0):
pass
else:
dp[i][j]=min(dp[i][j],dp[i-1][k]+arr[i][1]*j)
mini=999999999999999999999999999
for i in range(3):
mini=min(mini,dp[-1][i])
print(mini)
``` | output | 1 | 61,554 | 8 | 123,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,555 | 8 | 123,110 |
Tags: dp
Correct Solution:
```
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
if __name__ == '__main__':
t = int(input())
results = []
for _ in range(t):
n = int(input())
hp = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
dp[0] = [0, hp[0][1], hp[0][1]*2]
for i in range(1, n):
dp[i] = [(hp[i][1] * j + min([dp[i-1][k] for k in range(3) if hp[i][0] + j != hp[i-1][0] + k])) for j in range(3)]
results.append(min(dp[-1]))
print(*results, sep='\n')
``` | output | 1 | 61,555 | 8 | 123,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,556 | 8 | 123,112 |
Tags: dp
Correct Solution:
```
import sys,os,io
from sys import stdin
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
n = int(input())
a = []
b = []
for i in range(n):
l,r = [int(x) for x in input().split()]
a.append(l)
b.append(r)
dp = [[float('inf'),float('inf'),float('inf')] for i in range(n)]
dp[0][0]=0
dp[0][1] = b[0]
dp[0][2] = b[0]*2
for i in range(1,n):
for j1 in range(3):
for j2 in range(3):
if a[i]+j1!=a[i-1]+j2:
dp[i][j1] = min(dp[i][j1], dp[i-1][j2] + j1*b[i])
# for i in dp:
# print(*i)
print(min(dp[-1]))
``` | output | 1 | 61,556 | 8 | 123,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,557 | 8 | 123,114 |
Tags: dp
Correct Solution:
```
import sys
from math import inf as inf
for _ in range(int(input())):
n=int(sys.stdin.readline())
dp=[[inf,inf,inf] for i in range(n+1)]
a=[]
for i in range(n):
a.append(list(map(int,sys.stdin.readline().split())))
dp[0][0]=0
dp[0][1]=a[0][1]
dp[0][2]=2*a[0][1]
for i in range(1,n):
for j in range(3):
for k in range(3):
if a[i][0] + j != a[i-1][0] + k:
dp[i][j]=min(dp[i][j],dp[i-1][k] + j*a[i][1])
# print(dp)
print(min(dp[n-1]))
``` | output | 1 | 61,557 | 8 | 123,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,558 | 8 | 123,116 |
Tags: dp
Correct Solution:
```
from sys import stdin
from math import inf
q = int(stdin.readline())
for _ in range(q):
n = int(stdin.readline())
dp = [[inf for i in range(3)] for j in range(n)]
p = 0
for i in range(n):
a, b = map(int, stdin.readline().split())
if i == 0:
dp[i][0] = 0
dp[i][1] = b
dp[i][2] = 2*b
else:
if p != a: dp[i][0] = min(dp[i][0], dp[i-1][0])
if p + 1 != a: dp[i][0] = min(dp[i][0], dp[i-1][1])
if p + 2 != a: dp[i][0] = min(dp[i][0], dp[i-1][2])
if p != a + 1: dp[i][1] = min(dp[i][1], dp[i-1][0] + b)
if p + 1 != a + 1: dp[i][1] = min(dp[i][1], dp[i-1][1] + b)
if p + 2 != a + 1: dp[i][1] = min(dp[i][1], dp[i-1][2] + b)
if p != a + 2: dp[i][2] = min(dp[i][2], dp[i-1][0] + 2*b)
if p + 1 != a + 2: dp[i][2] = min(dp[i][2], dp[i-1][1] + 2*b)
if p + 2 != a + 2: dp[i][2] = min(dp[i][2], dp[i-1][2] + 2*b)
p = a
print(min(dp[n-1]))
``` | output | 1 | 61,558 | 8 | 123,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,559 | 8 | 123,118 |
Tags: dp
Correct Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
for j in range(int(input())):
n=int(input())
vals=[];price=[];pairs=[];dict1={}
for s in range(n):
a,b=map(int,input().split())
vals.append(a)
price.append(b)
dp=[0,price[0],2*price[0]]
for s in range(1,n):
dp0=[]
for b in range(3):
new=vals[s]+b
p=b*price[s]
minval=sum(dp)
minval+=p
for i in range(3):
if vals[s]+b!=vals[s-1]+i:
newp=dp[i]+p
if newp<minval:
minval=newp
dp0.append(minval)
dp=dp0
print(min(dp))
``` | output | 1 | 61,559 | 8 | 123,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is a_i. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition a_{i-1} β a_i holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay b_i rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
Input
The first line contains one integer q (1 β€ q β€ 3 β
10^5) β the number of queries.
The first line of each query contains one integers n (1 β€ n β€ 3 β
10^5) β the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i-th line contains two integers a_i and b_i (1 β€ a_i, b_i β€ 10^9) β the length of the i-th board and the price for increasing it by 1, respectively.
It is guaranteed that sum of all n over all queries not exceed 3 β
10^5.
It is guaranteed that answer to each query will not exceed 10^{18}.
Output
For each query print one integer β the minimum number of rubles you have to spend to make the fence great.
Example
Input
3
3
2 4
2 1
3 5
3
2 3
2 10
2 6
4
1 7
3 3
2 6
1000000000 2
Output
2
9
0
Note
In the first query you have to increase the length of second board by 2. So your total costs if 2 β
b_2 = 2.
In the second query you have to increase the length of first board by 1 and the length of third board by 1. So your total costs if 1 β
b_1 + 1 β
b_3 = 9.
In the third query the fence is great initially, so you don't need to spend rubles. | instruction | 0 | 61,560 | 8 | 123,120 |
Tags: dp
Correct Solution:
```
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
# import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
# @mt
def slv(N, AB):
memo = [0, AB[0][1], AB[0][1]*2]
for i in range(1, N):
a, b = AB[i]
a1, _ = AB[i-1]
memo2 = [0] * 3
for j in range(3):
tmp = 1e+1000
for k in range(3):
if a + j != a1 + k:
tmp = min(tmp, memo[k])
memo2[j] = tmp + j * b
memo = memo2
return min(memo)
def main():
Q = read_int()
for _ in range(Q):
N = read_int()
AB = [read_int_n() for _ in range(N)]
print(slv(N, AB))
# N = 100
# AB = [[1000000000, 1000000000] for _ in range(N)]
# print(slv(N, AB))
if __name__ == '__main__':
main()
``` | output | 1 | 61,560 | 8 | 123,121 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.