message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0 | instruction | 0 | 93,735 | 9 | 187,470 |
Tags: dp, implementation, sortings
Correct Solution:
```
import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().split()))
psa = [0 for i in range(n)]
for j in range(n-1, -1, -1):
if a[j] != 0:
if j < n-1:
psa[j+1] -= 1
if j - a[j] + 1 < 0:
psa[0] += 1
else:
psa[j-a[j] + 1] += 1
for j in range(1, n):
psa[j] += psa[j-1]
for j in range(n):
if psa[j] > 0:
print(1, end=' ')
else:
print(0, end=' ')
print('')
``` | output | 1 | 93,735 | 9 | 187,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0 | instruction | 0 | 93,736 | 9 | 187,472 |
Tags: dp, implementation, sortings
Correct Solution:
```
t = int(input())
for _t in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
x = 0
for j in range(n - 1, -1, -1):
if a[j] > x:
x = a[j]
if x > 0:
b[j] = 1
x -= 1
for i in range(n):
print(b[i], end=" ")
print()
``` | output | 1 | 93,736 | 9 | 187,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0 | instruction | 0 | 93,737 | 9 | 187,474 |
Tags: dp, implementation, sortings
Correct Solution:
```
from sys import stdin
import math
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
dp = [0] * n
nl = 0
for i in range(n-1, -1, -1):
nl = max(nl, a[i])
dp[i] = int(nl > 0)
nl -= 1
print(*dp)
``` | output | 1 | 93,737 | 9 | 187,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0 | instruction | 0 | 93,738 | 9 | 187,476 |
Tags: dp, implementation, sortings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
o=[0]*n
remain=0
for i in range(n-1,-1,-1):
if l[i]>0 or remain>0:
o[i]=1
remain=max(remain-1,l[i]-1)
print(*o,sep=" ")
``` | output | 1 | 93,738 | 9 | 187,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
t = int(input())
while t:
t-=1
n = int(input())
a=[int(i) for i in input().split()]
b = [0]*n
if a[n-1]>=n:
for i in range(n):
print("1",end=" ")
print()
else:
i=n-1
c=-1
while i>=0:
if a[i]>c:
c=a[i]
if c>0:
b[i]=1
c-=1
i-=1
for i in range(n):
print(b[i],end=" ")
print()
``` | instruction | 0 | 93,739 | 9 | 187,478 |
Yes | output | 1 | 93,739 | 9 | 187,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
def answer():
ans=[0 for i in range(n)]
for i in range(n):
ans[i]=max(a[i],ans[i])
inc=0
for i in range(n-1,-1,-1):
if(inc+ans[i]):
inc=max(ans[i],inc)
ans[i]=1
else:
ans[i]=0
inc+=1
inc-=1
return ans
for T in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
print(*answer())
``` | instruction | 0 | 93,740 | 9 | 187,480 |
Yes | output | 1 | 93,740 | 9 | 187,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
import math
import sys
import collections
import bisect
import string
import time
def get_ints():return map(int, sys.stdin.readline().strip().split())
def get_list():return list(map(int, sys.stdin.readline().strip().split()))
def get_string():return sys.stdin.readline().strip()
for t in range(int(input())):
n = int(input())
arr = get_list()
ans=[0]*n
pos=n
for i in range(n-1,-1,-1):
pos=min(i-arr[i],pos)
if i>pos:
ans[i]=1
print(*ans)
``` | instruction | 0 | 93,741 | 9 | 187,482 |
Yes | output | 1 | 93,741 | 9 | 187,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
def get_result(ar, n):
stack = []
ans = [0] * n
for i, val in enumerate(ar):
if val ==0:
stack.append(i)
continue
ans[i] = 1
val -= 1
prev = val
while stack and i-stack[-1] <= prev and val:
top = stack.pop()
ans[top] = 1
val -= 1
print(*ans)
def main():
test = int(input())
for _ in range(test):
n = int(input())
arr = list(map(int, input().split(' ')))
get_result(arr, n)
if __name__ == "__main__":
main()
``` | instruction | 0 | 93,742 | 9 | 187,484 |
Yes | output | 1 | 93,742 | 9 | 187,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
import sys
def scan(input_type='int'):
if input_type == 'int':
return list(map(int, sys.stdin.readline().strip().split()))
else:
return list(map(str, sys.stdin.readline().strip()))
def solution():
for _ in range(int(input())):
n = int(input())
a = scan()
b = [0]*n
i = n-1
while i > -1:
# print(1)
if a[i] > 0:
j = i
while j > -1 and j > i - a[i]:
b[j] = 1
# print(0)
j -= 1
i -= a[i]
else:
i -= 1
a = [print(i, end=' ') for i in b]
print()
if __name__ == '__main__':
solution()
``` | instruction | 0 | 93,743 | 9 | 187,486 |
No | output | 1 | 93,743 | 9 | 187,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
import math
def getint():
return [int(i) for i in input().split()]
def getstr():
return [str(i) for i in input().split()]
#--------------------------------------------------------------------------
def solve():
n=int(input())
a=getint()
ans=""
l=0
for i in range(n-1,-1,-1):
if a[i]==0:
if l<=n-1-i:
ans+="0"
l+=1
else:
leng=min(a[i]-l+n-1-i,n-l)
if leng<0:
leng=0
l+=leng
ans+="1"*leng
print(i,ans)
print(" ".join(ans[::-1]))
#--------------------------------------------------------------------------
for _ in range(int(input())):
solve()
``` | instruction | 0 | 93,744 | 9 | 187,488 |
No | output | 1 | 93,744 | 9 | 187,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
def solve(t):
n = int(input())
arr = [int(x) for x in input().split()]
ans = [0 for _ in arr]
for i, a in enumerate(arr):
for j in range(a):
ans[i - j] = 1
print(' '.join(map(str, ans)))
T = int(input())
for t in range(1, T + 1):
solve(t)
``` | instruction | 0 | 93,745 | 9 | 187,490 |
No | output | 1 | 93,745 | 9 | 187,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.
To bake a Napoleon cake, one has to bake n dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps n times:
* place a new cake layer on the top of the stack;
* after the i-th layer is placed, pour a_i units of cream on top of the stack.
When x units of cream are poured on the top of the stack, top x layers of the cake get drenched in the cream. If there are less than x layers, all layers get drenched and the rest of the cream is wasted. If x = 0, no layer gets drenched.
<image> The picture represents the first test case of the example.
Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 20 000). Description of the test cases follows.
The first line of each test case contains a single integer n (1 β€ n β€ 2 β
10^5) β the number of layers in the cake.
The second line of each test case contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ n) β the amount of cream poured on the cake after adding each layer.
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print a single line with n integers. The i-th of the integers should be equal to 1 if the i-th layer from the bottom gets drenched, and 0 otherwise.
Example
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1
0 1 1 1 1 1 0 0 1 1
0 0 0
Submitted Solution:
```
t = int(input())
for i in range(t):
n = int(input())
lst = list(map(int,input().split()))
res = [0]*n
for i in range(n):
if lst[i] == 0:
pass
else:
j = i
k = 0
while k < lst[i] and j >= 0:
res[j] = 1
k+=1
j-=1
print(res)
``` | instruction | 0 | 93,746 | 9 | 187,492 |
No | output | 1 | 93,746 | 9 | 187,493 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street.
The street, where the Lou Who family lives can be represented as n consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets).
After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food.
The Lou Whos want to spend no more than t time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional k kilos of sweets.
Cindy Lou wants to know the minimum number of k kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street.
Your task is to write a program that will determine the minimum possible value of k.
Input
The first line of the input contains two space-separated integers n and t (2 β€ n β€ 5Β·105, 1 β€ t β€ 109). The second line of the input contains n characters, the i-th of them equals "H" (if the i-th segment contains a house), "S" (if the i-th segment contains a shop) or "." (if the i-th segment doesn't contain a house or a shop).
It is guaranteed that there is at least one segment with a house.
Output
If there isn't a single value of k that makes it possible to give sweets to everybody in at most t units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of k.
Examples
Input
6 6
HSHSHS
Output
1
Input
14 100
...HHHSSS...SH
Output
0
Input
23 50
HHSS.......SSHHHHHHHHHH
Output
8
Note
In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back.
In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction.
In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home. | instruction | 0 | 93,800 | 9 | 187,600 |
Tags: binary search, greedy, implementation
Correct Solution:
```
def check(n, casas):
#print('n:',n)
global T,N,street
current = n
time = T
need = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
if need == 1:
last_house = ind
if need > 0 and current >= need:
#print('p',time, ind-last_house)
current -= need
casas -= need
need = 0
if casas > 0:
if (ind-last_house)*2 >= N-last_house-1:
time -= N-last_house-1 + N-ind-1
return time >= 0
time -= (ind-last_house)*2
else:
time -= ind-last_house
#print('lugar:',i,ind,current, time, need, last_house)
if casas == 0:
break
#print(time)
return time >= 0 and casas == 0
N,T = [int(i) for i in input().split()]
street = input().rstrip('.')
N = len(street)
C = street.count('H')
S = street.count('S')
l = max(C-S, 0)
r = 500005
#print(N, C)
while l < r:
mid = (l+r)//2
if check(mid, C):
r = mid
else:
l = mid + 1
print(l if l < 500005 else -1)
``` | output | 1 | 93,800 | 9 | 187,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street.
The street, where the Lou Who family lives can be represented as n consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets).
After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food.
The Lou Whos want to spend no more than t time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional k kilos of sweets.
Cindy Lou wants to know the minimum number of k kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street.
Your task is to write a program that will determine the minimum possible value of k.
Input
The first line of the input contains two space-separated integers n and t (2 β€ n β€ 5Β·105, 1 β€ t β€ 109). The second line of the input contains n characters, the i-th of them equals "H" (if the i-th segment contains a house), "S" (if the i-th segment contains a shop) or "." (if the i-th segment doesn't contain a house or a shop).
It is guaranteed that there is at least one segment with a house.
Output
If there isn't a single value of k that makes it possible to give sweets to everybody in at most t units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of k.
Examples
Input
6 6
HSHSHS
Output
1
Input
14 100
...HHHSSS...SH
Output
0
Input
23 50
HHSS.......SSHHHHHHHHHH
Output
8
Note
In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back.
In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction.
In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home.
Submitted Solution:
```
def check(n, casas):
global T
current = n
time = T + 1
need = 0
walk = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
if need == 1:
last_house = ind
if need > 0 and current >= need:
#print(time, ind-last_house)
current -= need
casas -= need
walk = 0
need = 0
if ind > last_house:
time -= (ind-last_house) * 2
if casas == 0:
time += 1
#print('lugar:',i,current, time, need, walk)
if casas == 0:
break
#print(T-time)
return time > 0 and casas == 0
N,T = [int(i) for i in input().split()]
street = input()
C = street.count('H')
l = 0
r = 500005
while l < r:
mid = (l+r)//2
if check(mid, C):
r = mid
else:
l = mid + 1
print(l)
``` | instruction | 0 | 93,801 | 9 | 187,602 |
No | output | 1 | 93,801 | 9 | 187,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street.
The street, where the Lou Who family lives can be represented as n consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets).
After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food.
The Lou Whos want to spend no more than t time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional k kilos of sweets.
Cindy Lou wants to know the minimum number of k kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street.
Your task is to write a program that will determine the minimum possible value of k.
Input
The first line of the input contains two space-separated integers n and t (2 β€ n β€ 5Β·105, 1 β€ t β€ 109). The second line of the input contains n characters, the i-th of them equals "H" (if the i-th segment contains a house), "S" (if the i-th segment contains a shop) or "." (if the i-th segment doesn't contain a house or a shop).
It is guaranteed that there is at least one segment with a house.
Output
If there isn't a single value of k that makes it possible to give sweets to everybody in at most t units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of k.
Examples
Input
6 6
HSHSHS
Output
1
Input
14 100
...HHHSSS...SH
Output
0
Input
23 50
HHSS.......SSHHHHHHHHHH
Output
8
Note
In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back.
In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction.
In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home.
Submitted Solution:
```
def check(n, casas):
#print('n:',n)
global T,N,street
current = n
time = T
need = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
if need == 1:
last_house = ind
if need > 0 and current >= need:
#print('p',time, ind-last_house)
current -= need
casas -= need
need = 0
if casas > 0:
if (ind-last_house)*2 >= N-last_house-1:
time -= N-last_house-1 + N-ind-1
return time >= 0
time -= (ind-last_house)*2
else:
time -= ind-last_house
#print('lugar:',i,ind,current, time, need, last_house)
if casas == 0:
break
#print(time)
return time >= 0 and casas == 0
N,T = [int(i) for i in input().split()]
street = input().rstrip('.')
N = len(street)
C = street.count('H')
S = street.count('S')
l = C-S
r = 500005
#print(N, C)
while l < r:
mid = (l+r)//2
if check(mid, C):
r = mid
else:
l = mid + 1
print(l if l < 500005 else -1)
``` | instruction | 0 | 93,802 | 9 | 187,604 |
No | output | 1 | 93,802 | 9 | 187,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street.
The street, where the Lou Who family lives can be represented as n consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets).
After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food.
The Lou Whos want to spend no more than t time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional k kilos of sweets.
Cindy Lou wants to know the minimum number of k kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street.
Your task is to write a program that will determine the minimum possible value of k.
Input
The first line of the input contains two space-separated integers n and t (2 β€ n β€ 5Β·105, 1 β€ t β€ 109). The second line of the input contains n characters, the i-th of them equals "H" (if the i-th segment contains a house), "S" (if the i-th segment contains a shop) or "." (if the i-th segment doesn't contain a house or a shop).
It is guaranteed that there is at least one segment with a house.
Output
If there isn't a single value of k that makes it possible to give sweets to everybody in at most t units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of k.
Examples
Input
6 6
HSHSHS
Output
1
Input
14 100
...HHHSSS...SH
Output
0
Input
23 50
HHSS.......SSHHHHHHHHHH
Output
8
Note
In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back.
In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction.
In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home.
Submitted Solution:
```
def check(n, casas):
#print('n:',n)
global T
current = n
time = T
need = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
if need == 1:
last_house = ind
if need > 0 and current >= need:
#print('p',time, ind-last_house)
current -= need
casas -= need
need = 0
if ind > last_house:
time -= ind-last_house
if casas > 0:
time -= ind-last_house
#print('lugar:',i,ind,current, time, need, last_house)
if casas == 0:
break
#print(time)
return time >= 0 and casas == 0
N,T = [int(i) for i in input().split()]
street = input()
C = street.count('H')
l = 0
r = 500005
#print(N, C)
while l < r:
mid = (l+r)//2
if check(mid, C):
r = mid
else:
l = mid + 1
print(l if l < 500005 else -1)
``` | instruction | 0 | 93,803 | 9 | 187,606 |
No | output | 1 | 93,803 | 9 | 187,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"
Dr. Suess, How The Grinch Stole Christmas
Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street.
The street, where the Lou Who family lives can be represented as n consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets).
After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food.
The Lou Whos want to spend no more than t time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional k kilos of sweets.
Cindy Lou wants to know the minimum number of k kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street.
Your task is to write a program that will determine the minimum possible value of k.
Input
The first line of the input contains two space-separated integers n and t (2 β€ n β€ 5Β·105, 1 β€ t β€ 109). The second line of the input contains n characters, the i-th of them equals "H" (if the i-th segment contains a house), "S" (if the i-th segment contains a shop) or "." (if the i-th segment doesn't contain a house or a shop).
It is guaranteed that there is at least one segment with a house.
Output
If there isn't a single value of k that makes it possible to give sweets to everybody in at most t units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of k.
Examples
Input
6 6
HSHSHS
Output
1
Input
14 100
...HHHSSS...SH
Output
0
Input
23 50
HHSS.......SSHHHHHHHHHH
Output
8
Note
In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back.
In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction.
In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home.
Submitted Solution:
```
def check(n, casas):
#print('n:',n)
global T,N,street
current = n
time = T
need = 0
last_house = 0
for ind, i in enumerate(street):
time -= 1
if i == 'S':
current += 1
elif i == 'H':
need += 1
if need == 1:
last_house = ind
if need > 0 and current >= need:
#print('p',time, ind-last_house)
current -= need
casas -= need
need = 0
if casas > 0:
if (ind-last_house)*2 >= N-last_house-1:
time -= N-last_house-1 + N-ind-1
return time >= 0
time -= (ind-last_house)*2
else:
time -= ind-last_house
#print('lugar:',i,ind,current, time, need, last_house)
if casas == 0:
break
#print(time)
return time >= 0 and casas == 0
N,T = [int(i) for i in input().split()]
street = input().rstrip('.')
N = len(street)
C = street.count('H')
S = street.count('S')
l = C-S
r = C
#print(N, C)
while l < r:
mid = (l+r)//2
if check(mid, C):
r = mid
else:
l = mid + 1
print(l if l < 500005 else -1)
``` | instruction | 0 | 93,804 | 9 | 187,608 |
No | output | 1 | 93,804 | 9 | 187,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
from sys import stdout
def bsearch(l, r):
while l < r:
mid = (l+r)//2
print("%d %d %d"%(1, mid, mid+1))
stdout.flush()
resp = input()
if resp == "TAK":
r = mid
else:
l = mid+1
return l
n, k = map(int, input().split())
x = bsearch(1, n)
y = bsearch(x+1, n)
print('%d %d %d'%(1, y, x))
stdout.flush()
resp = input()
if resp == "NIE":
y = bsearch(1, x-1)
print('%d %d %d'%(2, x, y))
``` | instruction | 0 | 94,074 | 9 | 188,148 |
No | output | 1 | 94,074 | 9 | 188,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
def do_something( some_value ):
if some_value < 1:
return False
print(1, some_value, some_value+1)
stdout.flush()
response = input()
if response == "TAK":
return True
else:
return False
def bin_search( first, last ):
middle = 0
while first < last:
middle = (first + last) / 2
if do_something(middle):
last = middle
else:
first = middle
return middle
def main():
n = k = 0
n,k = map(int, input().split())
firstdish = bin_search(1,n)
seconddish = bin_search(1,firstdish-1)
if not do_something(seconddish):
seconddish = bin_search(firstdish+1, n)
print(2, firstdish, seconddish)
``` | instruction | 0 | 94,075 | 9 | 188,150 |
No | output | 1 | 94,075 | 9 | 188,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
def bsearch(l, r):
while l < r:
mid = (l + r) // 2
print(1, mid, mid + 1)
x = 1 if input() == 'TAK' else 0
if x:
r = mid
else:
l = mid + 1
return l
n, k = map(int, input().split())
x = bsearch(1, n)
print(1, x)
a = bsearch(1, x - 1)
print(2, x, a)
if input() == 'TAK':
print(1, a)
else:
print(1, bsearch(x + 1, n))
``` | instruction | 0 | 94,076 | 9 | 188,152 |
No | output | 1 | 94,076 | 9 | 188,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem. In the output section below you will see the information about flushing the output.
On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in ViΔkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.
In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.
The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 β€ x, y β€ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value <image> is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says Β«TAKΒ» to Leha, if <image>, and Β«NIEΒ» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.
Help Leha to solve this problem!
Input
There are two numbers n and k (2 β€ k β€ n β€ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.
Output
If you want to provide an answer, output a string of the form 2 x y (1 β€ x, y β€ n, x β y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.
Interaction
While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 β€ x, y β€ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.
After each query jury's program will print one line Β«TAKΒ» or Β«NIEΒ» (without quotes) in input stream depending on the girl's answer.
To flush you can use (just after printing an integer and end-of-line):
* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* see the documentation for other languages.
Hacking
For hacking you should write numbers n and k (2 β€ k β€ n β€ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 β€ ai β€ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.
Example
Input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
Output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note
There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value <image>. For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case <image>.
Let Leha asks Noora about the next couple of dishes:
* x = 1, y = 2, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |2 - 2|
* x = 2, y = 1, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |1 - 2|
* x = 1, y = 3, then he'll recieve Β«NIEΒ» answer, because |1 - 2| > |3 - 3|
* x = 3, y = 1, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |1 - 2|
* x = 2, y = 3, then he'll recieve Β«TAKΒ» answer, because |2 - 2| β€ |3 - 3|
* x = 3, y = 2, then he'll recieve Β«TAKΒ» answer, because |3 - 3| β€ |2 - 2|
According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.
Submitted Solution:
```
from sys import stdout
def do_something( some_value ):
if some_value < 1:
return False
print(1, some_value, some_value+1)
response = input()
if response == "TAK":
return True
else:
return False
def bin_search( first, last ):
middle = last
while first < last:
middle = (first + last) // 2
if do_something(middle):
last = middle
else:
first = middle + 1
return middle
def main():
n = k = 0
n,k = map(int, input().split())
firstdish = bin_search(1,n)
seconddish = bin_search(1,firstdish-1)
if not do_something(seconddish):
seconddish = bin_search(firstdish+1, n)
print(2, firstdish, seconddish)
main()
``` | instruction | 0 | 94,077 | 9 | 188,154 |
No | output | 1 | 94,077 | 9 | 188,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,442 | 9 | 188,884 |
Tags: data structures, implementation
Correct Solution:
```
import sys
from heapq import heappush , heappop , heapify
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip('\n')
n , k = get_ints()
khana = get_array()
rate = get_array()
paisa = [ [j,i] for i , j in enumerate(rate) ]
paisa.sort()
i = 0
for _ in range(k):
thali , plate = get_ints()
thali-=1
if khana[thali] >=plate:
print(rate[thali]*plate)
khana[thali] -= plate
else:
#print('thali to kam hai')
kharcha = khana[thali]*rate[thali]
plate -= khana[thali]
khana[thali] = 0
#print(khana)
while i < n:
rupaya , jagah = paisa[i][0] , paisa[i][1]
if khana[jagah] >= plate:
kharcha += rate[jagah]*plate
khana[jagah] -= plate
plate = 0
break
else:
kharcha += rate[jagah]*khana[jagah]
plate -= khana[jagah]
khana[jagah] = 0
i+=1
if plate == 0:
print(kharcha)
else:
print(0)
#is this brute force hai?
#priority queue ka koi idea?
``` | output | 1 | 94,442 | 9 | 188,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,443 | 9 | 188,886 |
Tags: data structures, implementation
Correct Solution:
```
import sys
from collections import deque
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input().split()))
ip = lambda : input()
fi = lambda : float(input())
li = lambda : list(input())
pr = lambda x : print(x)
n,m = il()
a = il()
c = il()
z = [[c[i],i] for i in range (n)]
z.sort()
z = deque(z)
for _ in range(m) :
x,y = il()
ans = 0
x -=1
t = min(y,a[x])
a[x] -= t
ans += t*c[x]
y -= t
while y > 0 and z :
f = z[0]
t = min(a[f[1]],y)
a[f[1]] -= t
y -= t
ans += f[0]*t
if a[f[1]] == 0 :
z.popleft()
if y == 0 :
print(ans)
else :
print(0)
``` | output | 1 | 94,443 | 9 | 188,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,444 | 9 | 188,888 |
Tags: data structures, implementation
Correct Solution:
```
n,m=map(int,input().split())
aa=list(map(int,input().split()))
c=list(map(int,input().split()))
a=[(j,i) for i,j in enumerate(c)]
a.sort();
ans=[];su=0
for _ in range(m):
cost=0
i,j=map(int,input().split())
if j>aa[i-1]:cost+=aa[i-1]*c[i-1];j-=aa[i-1];aa[i-1]=0
else:cost+=j*c[i-1];aa[i-1]-=j;j=0
ii=su
#print(_,cost,j)
while j>0 and ii<n:
z,k=a[ii]
if aa[k]<=0:ii+=1;su=ii;continue
if j>aa[k]:cost+=aa[k]*c[k];j-=aa[k];aa[k]=0
else:cost+=j*c[k];aa[k]-=j;j=0
ii+=1
#print(_,k,aa[k],j)
if ii==n and j!=0:cost=0
#print(_,ii,i,cost)
ans.append(cost)
print(*ans,sep='\n')
``` | output | 1 | 94,444 | 9 | 188,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,445 | 9 | 188,890 |
Tags: data structures, implementation
Correct Solution:
```
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
costs = sorted([(i, cost) for i, cost in enumerate(c)],key=lambda x: (x[1], x[0]))
co = 0
for i in range(m):
t, d = map(int, input().split())
t -= 1
price = 0
if a[t] > d:
price = d*c[t]
a[t] -= d
else:
price = a[t]*c[t]
d -= a[t]
a[t] = 0
while d > 0 and co < n:
ai, cost = costs[co]
if a[ai] > d:
price += d*cost
a[ai] -= d
d = 0
else:
price += a[ai]*cost
d -= a[ai]
a[ai] = 0
co += 1
if d > 0:
price = 0
print(price)
``` | output | 1 | 94,445 | 9 | 188,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,446 | 9 | 188,892 |
Tags: data structures, implementation
Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[]
for i in range(n):
p.append([i,c[i]])
p=sorted(p,key=lambda item:item[1])
zer0=0
for i in range(m):
# ans=
#ans
t,d=map(int,input().split())
t-=1
if a[t]>=d:
print(c[t]*d)
a[t]-=d
continue
else:
ans=0
# ii=zer0
req=d
req-=a[t]
ans+=(c[t]*a[t])
a[t]=0
if req>0:
for j in range(zer0,n):
y=min(req,a[p[j][0]])
ans+=(p[j][1]*y)
a[p[j][0]]-=y
req-=y
if a[p[j][0]]==0:
zer0+=1
if req==0:
break
# print(req,ans)
if req!=0:
print(0)
continue
else:
print(ans)
``` | output | 1 | 94,446 | 9 | 188,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,447 | 9 | 188,894 |
Tags: data structures, implementation
Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[]
for i in range(n):
p.append([i,c[i]])
p=sorted(p,key=lambda item:item[1])
zer0=0
for i in range(m):
# ans=
t,d=map(int,input().split())
t-=1
if a[t]>=d:
print(c[t]*d)
a[t]-=d
continue
else:
ans=0
# ii=zer0
req=d
req-=a[t]
ans+=(c[t]*a[t])
a[t]=0
if req>0:
for j in range(zer0,n):
y=min(req,a[p[j][0]])
ans+=(p[j][1]*y)
a[p[j][0]]-=y
req-=y
if a[p[j][0]]==0:
zer0+=1
if req==0:
break
# print(req,ans)
if req!=0:
print(0)
continue
else:
print(ans)
``` | output | 1 | 94,447 | 9 | 188,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,448 | 9 | 188,896 |
Tags: data structures, implementation
Correct Solution:
```
n, m = map(int, input().split())
dish = list(map(int, input().split()))
cost = list(map(int, input().split()))
scost = []
for i in range(n):
scost.append([cost[i], dish[i], i])
scost = sorted(scost)
cur = 0
for i in range(m):
x, y = map(int, input().split())
x -= 1
price = 0
if dish[x] >= y:
price += cost[x] * y
dish[x] -= y
y = 0
else:
price += cost[x] * dish[x]
y -= dish[x]
dish[x] = 0
while y > 0:
try:
tmp = scost[cur][-1]
if dish[tmp] >= y:
price += cost[tmp] * y
dish[tmp] -= y
y = 0
else:
price += cost[tmp] * dish[tmp]
y -= dish[tmp]
dish[tmp] = 0
cur += 1
except IndexError:
price = 0
y = 0
print(price)
``` | output | 1 | 94,448 | 9 | 188,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058. | instruction | 0 | 94,449 | 9 | 188,898 |
Tags: data structures, implementation
Correct Solution:
```
from heapq import*
R=lambda:[*map(int,input().split())]
n,m=R()
a,c=R(),R()
b=[*zip(c,range(n))]
heapify(b)
for _ in[0]*m:
t,d=R();t-=1;r=0
e=min(a[t],d);a[t]-=e;d-=e;r+=c[t]*e
while d and b:
x,t=b[0]
e=min(a[t],d);a[t]-=e;d-=e;r+=x*e
if a[t]==0:heappop(b)
print((0,r)[d==0])
``` | output | 1 | 94,449 | 9 | 188,899 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
R=lambda:[*map(int,input().split())]
n,m=R()
a,c=R(),R()
def f():global r,d;e=min(a[t],d);a[t]-=e;d-=e;r+=x*e
b=sorted(zip(c,range(n)))
i=0
for _ in[0]*m:
t,d=R();t-=1;r=0;x=c[t];f()
while d and i<n:x,t=b[i];f();i+=a[t]==0
print((r,0)[d>0])
``` | instruction | 0 | 94,450 | 9 | 188,900 |
Yes | output | 1 | 94,450 | 9 | 188,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
def main():
n,m = map(int,input().split())
remain = list(map(int,input().split()))
cost = list(map(int,input().split()))
stack = []
for i in range(n):
stack.append((cost[i],i))
stack.sort()
stack.reverse()
for i in range(m):
t,d = map(int,input().split())
cst = 0
if remain[t-1] >= d:
remain[t-1] -= d
cst += d*cost[t-1]
else:
r = d - remain[t-1]
cst += remain[t-1]*cost[t-1]
remain[t-1] = 0
while r != 0:
if not stack:
cst = 0
break
c = stack.pop()
if remain[c[1]] >= r:
cst += r*cost[c[1]]
remain[c[1]] -= r
r = 0
if remain[c[1]] > 0:
stack.append(c)
else:
r -= remain[c[1]]
cst += remain[c[1]]*cost[c[1]]
remain[c[1]] = 0
print (cst)
main()
``` | instruction | 0 | 94,451 | 9 | 188,902 |
Yes | output | 1 | 94,451 | 9 | 188,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading
from heapq import *
def main():
n,m=map(int,input().split())
a = [*map(int,input().split())]
c = [*map(int,input().split())]
D = []
for i in range(n):
D.append([c[i],i])
D.sort(key = lambda z: z[0])
q = deque(D)
for i in range(m):
ans = 0
t, d = map(int,input().split()); t-=1
if a[t] > d:
ans = d * c[t]
a[t] -= d
d = 0
else:
ans = a[t] * c[t]
d -= a[t]
a[t] = 0
while q:
if a[q[0][1]] >= d:
ans += c[q[0][1]] * d
a[q[0][1]]-=d
d = 0
if a[q[0][1]] == 0: q.popleft()
break
else:
ans += c[q[0][1]] * a[q[0][1]]
d -= a[q[0][1]]
a[q[0][1]] = 0
q.popleft()
if d > 0: print(0)
else:print(ans)
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")
# endregion
if __name__ == "__main__":
"""sys.setrecursionlimit(400000)
threading.stack_size(40960000)
thread = threading.Thread(target=main)
thread.start()"""
main()
``` | instruction | 0 | 94,452 | 9 | 188,904 |
Yes | output | 1 | 94,452 | 9 | 188,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
n , m = map( int , input().split() )
a = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
s = [(i,c[i]) for i in range(n)]
s = sorted(s , key = lambda x:(x[1],x[0]))
cheapest = 0
for _ in range(m):
cost = 0
t , d = map(int , input().split())
minimo = min(a[t-1],d)
cost+= minimo*c[t-1]
a[t-1]-=minimo
d-=minimo
while(d>0 and cheapest < n): #O salΓ, o agote productos
i_min = s[cheapest][0]
cost_min = s[cheapest][1]
minimo = min(a[i_min] , d)
a[i_min]-= minimo
cost+= cost_min*minimo
d-= minimo
if(a[i_min]==0):
cheapest+=1
if(d == 0):
print(cost)
else:
print(0)
``` | instruction | 0 | 94,453 | 9 | 188,906 |
Yes | output | 1 | 94,453 | 9 | 188,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
import sys
import math
def read_int():
return int(input().strip())
def read_int_list():
return list(map(int,input().strip().split()))
def read_string():
return input().strip()
def read_string_list(delim=" "):
return input().strip().split(delim)
###### Author : Samir Vyas #######
###### Write Code Below #######
import heapq
n,k = read_int_list()
remains = read_int_list()
costs = read_int_list()
total = sum(remains)
#heap has [cost,index]
heap = []
for i in range(n):
heap.append([costs[i],i])
heapq.heapify(heap)
for i in range(k):
index, demanded_quant = read_int_list()
index -= 1
cost = 0
#if total is 0 then cannot do anythin
if total <= 0:
print(0)
continue
#give available
available_quant = min(remains[index], demanded_quant)
cost += costs[index]*available_quant
demanded_quant -= available_quant
remains[index] -= available_quant
total -= available_quant
#give as many cheapest as you can
while demanded_quant > 0 and len(heap) > 0:
index = heapq.heappop(heap)[1]
#if item is not remaining
if remains[index] <= 0:
continue
#if anything is remaining
available_quant = min(remains[index], demanded_quant)
cost += costs[index]*available_quant
demanded_quant -= available_quant
remains[index] -= available_quant
total -= available_quant
#push new entry to heap
if remains[index] > 0:
heapq.heappush(heap, [costs[index],index])
#if heap is empty then custommer won't pay
if len(heap) == 0:
print(0)
else:
print(cost)
``` | instruction | 0 | 94,454 | 9 | 188,908 |
No | output | 1 | 94,454 | 9 | 188,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
def get_i(l):
m=10000000000000
index=0
for i in range(len(l)):
if l[i]<m and l[i]!=0:
m=l[i]
index=i
return index
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=list(map(int,input().split()))
s=sum(a)
for i in range(m):
total=0
t,d=map(int,input().split())
t-=1
while d!=0 and s!=0:
if s-a[t]>=0:
if a[t]-d>0:
a[t]-=d
s-=d
total+=d*c[t]
break
elif a[t]>0:
s-=a[t]
d-=a[t]
total+=a[t]*c[t]
c[t]=0
a[t]=0
t=get_i(c)
else:
t=get_i(c)
else:
total=0
break
print(total)
``` | instruction | 0 | 94,455 | 9 | 188,910 |
No | output | 1 | 94,455 | 9 | 188,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
from bisect import*
R=lambda:[*map(int,input().split())]
n,m=R()
a,c=R(),R()
b=sorted(zip(c,range(n)))
for _ in[0]*m:
t,d=R();t-=1;r=0
if a[t]:e=min(a[t],d);a[t]-=e;d-=e;r+=c[t]*e;i=0
for x,j in b:
e=min(a[j],d);a[j]-=e;d-=e;r+=x*e
if d==0:break
i+=1
b[:i]=[]
print((0,r)[d==0])
``` | instruction | 0 | 94,456 | 9 | 188,912 |
No | output | 1 | 94,456 | 9 | 188,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant β "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.
Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.
Please determine the total cost for each of the m customers.
Input
The first line contains two integers n and m (1 β€ n, m β€ 10^5), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c_1, c_2, β¦, c_n (1 β€ c_i β€ 10^6), where c_i denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 β€ t_j β€ n, 1 β€ d_j β€ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.
Output
Print m lines. In the j-th line print the cost for the j-th customer.
Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
Note
In the first sample, 5 customers will be served as follows.
1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 β
3 + 1 β
2 + 1 β
2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 β
6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 β
2 + 3 β
2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 β
3 + 2 β
2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 β
3 + 3 β
6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 β
6 = 396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 β
6 + 666 β
6 + 6666 β
1 = 11058.
Submitted Solution:
```
n, m = map(int,input().split(' '))
kol = list(map(int,input().split(' ')))
prices = list(map(int,input().split(' ')))
for i in range(m):
tip, koli = map(int,input().split(' '))
chek = 0
while koli != 0:
if kol[tip-1] > 0:
kol[tip-1] -=1
chek += prices[tip-1]
elif sum(kol)>0:
pm = 0
for j in range(1,n):
if (kol[j] > 0) and (prices[j]<prices[pm]):
pm = j
chek += prices[pm]
kol[pm] -=1
else:
chek = 0
break
koli -= 1
print(chek)
``` | instruction | 0 | 94,457 | 9 | 188,914 |
No | output | 1 | 94,457 | 9 | 188,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,623 | 9 | 189,246 |
Tags: math
Correct Solution:
```
# cook your dish here
#jai_shree_raam
#jai_bajrang_bali
#this function is taken from GeekForGeeks
import math
from collections import defaultdict as dfc
from collections import Counter
from math import gcd
def SOE(n):
prime=[True for i in range(n+1)]
p=2
while (p * p <= n):
if(prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p+=1
l=[]
for p in range(2, n+1):
if prime[p]:
l+=[p]
return l
def i1(): return int(input())#single integer
def i2(): return map(int,input().split())#two integers
def i3(): return list(map(int,input().split()))#list of integers
def i4(): return input()#string input
def i5(): return list(str(i1()))#list of characters of a string
def kbit(a, k):
if ((a>>(k-1)) and 1):
return True
else:
return False
for i in range(i1()):
r,b,d=i2()
k1=abs(r-b)
if(k1==0):
print("YES")
else:
k2=min(r,b)
c=k1//k2
if(k1%k2!=0):
c=c+1
if(c>d):
print("NO")
else:
print("YES")
``` | output | 1 | 94,623 | 9 | 189,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,624 | 9 | 189,248 |
Tags: math
Correct Solution:
```
for _ in range(int(input())):
a, b, d = map(int, input().split())
x, diff = min(a, b), abs(a - b)
if diff / x > d:
print("NO")
else:
print("YES")
``` | output | 1 | 94,624 | 9 | 189,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,625 | 9 | 189,250 |
Tags: math
Correct Solution:
```
from sys import stdin, stdout
for testcase in range(int(stdin.readline())):
r, b, d = list(map(int, stdin.readline().split()))
if d==0: print(["NO", "YES"][r==b])
else: print(["NO", "YES"][ abs(r-b)/d <= min(r, b) ])
``` | output | 1 | 94,625 | 9 | 189,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,626 | 9 | 189,252 |
Tags: math
Correct Solution:
```
for _ in range(int(input())):
a,b,c=map(int, input().split())
if b>a:
a,b=b,a
if b*(c+1)>=a:
print("YES")
else:
print("NO")
``` | output | 1 | 94,626 | 9 | 189,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,627 | 9 | 189,254 |
Tags: math
Correct Solution:
```
t=int(input())
for _ in range(t):
r,b,d=map(int,input().split())
if r==b:
print("YES")
elif r<b:
if b<=(1+d)*r:
print("YES")
else:
print("NO")
elif r>b:
if r<=(1+d)*b:
print("YES")
else:
print("NO")
else:
print("NO")
``` | output | 1 | 94,627 | 9 | 189,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,628 | 9 | 189,256 |
Tags: math
Correct Solution:
```
for _ in range(int(input())):
r, b, d = map(int, input().split())
if r > b:
r, b = b, r
if b <= r * (d+1) and b and r:
print('YES')
else:
print('NO')
``` | output | 1 | 94,628 | 9 | 189,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,629 | 9 | 189,258 |
Tags: math
Correct Solution:
```
t = int(input())
for _ in range(t):
r,b,d = [int(i) for i in input().strip().split()]
check = True
if d==0:
if r!=b:
print("NO")
check = False
else:
max_packets = min(r,b)
if (r+b-max_packets)>(d+1)*max_packets:
print("NO")
check = False
if check:
print("YES")
``` | output | 1 | 94,629 | 9 | 189,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b. | instruction | 0 | 94,630 | 9 | 189,260 |
Tags: math
Correct Solution:
```
t = int(input())
for _ in range(t):
r, b, d = map(int, input().split())
x = min(r, b) * d
print('YES' if abs(r - b) <= x else 'NO')
``` | output | 1 | 94,630 | 9 | 189,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b.
Submitted Solution:
```
import math
from sys import stdin,stdout
from operator import itemgetter
t=int(input())
for i in range(t):
n,m,d=map(int,stdin.readline().split())
flag=0
if(d==0):
if(n!=m):
flag=1
else:
mi=min(n,m)
k=mi*(d+1)
if(max(m,n)>k):
flag=1
if(flag==1):
print("NO")
else:
print("YES")
``` | instruction | 0 | 94,631 | 9 | 189,262 |
Yes | output | 1 | 94,631 | 9 | 189,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b.
Submitted Solution:
```
import sys,os,io
from sys import stdin,stdout
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left , bisect_right
import math
# input = stdin.readline
alphabets = list('abcdefghijklmnopqrstuvwxyz')
def isPrime(x):
for i in range(2,x):
if i*i>x:
break
if (x%i==0):
return False
return True
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
def power(x, y, p) :
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def SieveOfEratosthenes(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def si():
return input()
def prefix_sum(arr):
r = [0] * (len(arr)+1)
for i, el in enumerate(arr):
r[i+1] = r[i] + el
return r
def divideCeil(n,x):
if (n%x==0):
return n//x
return n//x+1
def ii():
return int(input())
def li():
return list(map(int,input().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
def power_set(L):
cardinality=len(L)
n=2 ** cardinality
powerset = []
for i in range(n):
a=bin(i)[2:]
subset=[]
for j in range(len(a)):
if a[-j-1]=='1':
subset.append(L[j])
powerset.append(subset)
powerset_orderred=[]
for k in range(cardinality+1):
for w in powerset:
if len(w)==k:
powerset_orderred.append(w)
return powerset_orderred
def fastPlrintNextLines(a):
# 12
# 3
# 1
#like this
#a is list of strings
print('\n'.join(map(str,a)))
def sortByFirstAndSecond(A):
A = sorted(A,key = lambda x:x[0])
A = sorted(A,key = lambda x:x[1])
return list(A)
#__________________________TEMPLATE__________________OVER_______________________________________________________
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
for _ in range(int(input())):
a,b,c = map(int,input().split())
if(a<b):
if(b> a*(c+1)):
print("NO")
else:
print("YES")
else:
if(a> b*(c+1)):
print("NO")
else:
print("YES")
# li = list(map(int,input().split()))
``` | instruction | 0 | 94,632 | 9 | 189,264 |
Yes | output | 1 | 94,632 | 9 | 189,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b.
Submitted Solution:
```
for _ in range(int(input())):
r,b,d=map(int,input().split())
z,y=min(r,b),max(r,b)
diff=y-z
zz=diff//z+(diff%z!=0)
if d<zz:
print("NO")
else:
print("YES")
``` | instruction | 0 | 94,633 | 9 | 189,266 |
Yes | output | 1 | 94,633 | 9 | 189,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b.
Submitted Solution:
```
import math
def getint():
return [int(i) for i in input().split()]
def getstr():
return [str(i) for i in input().split()]
#--------------------------------------------------------------------------
def solve():
a,b,k=getint()
a_=min(a,b)*(1+k)
b_=max(a,b)
if a_>=b_:
print("YES")
else:
print("NO")
#--------------------------------------------------------------------------
for _ in range(int(input())):
solve()
``` | instruction | 0 | 94,634 | 9 | 189,268 |
Yes | output | 1 | 94,634 | 9 | 189,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:
* has at least one red bean (or the number of red beans r_i β₯ 1);
* has at least one blue bean (or the number of blue beans b_i β₯ 1);
* the number of red and blue beans should differ in no more than d (or |r_i - b_i| β€ d)
Can you distribute all beans?
Input
The first line contains the single integer t (1 β€ t β€ 1000) β the number of test cases.
The first and only line of each test case contains three integers r, b, and d (1 β€ r, b β€ 10^9; 0 β€ d β€ 10^9) β the number of red and blue beans and the maximum absolute difference in each packet.
Output
For each test case, if you can distribute all beans, print YES. Otherwise, print NO.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
Example
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
Note
In the first test case, you can form one packet with 1 red and 1 blue bean. The absolute difference |1 - 1| = 0 β€ d.
In the second test case, you can form two packets: 1 red and 4 blue beans in the first packet and 1 red and 3 blue beans in the second one.
In the third test case, since b = 1, you can form only one packet with 6 red and 1 blue beans. The absolute difference |6 - 1| = 5 > d.
In the fourth test case, since d = 0 so each packet should contain the same number of red and blue beans, but r β b.
Submitted Solution:
```
from math import ceil
for tc in range(int(input())):
r,b,d = map(int,input().split())
mini = min(r,b)
maxi = max(r,b)
ans = ceil(maxi/mini)
if abs(ans-mini) <= d:
print('YES')
else:
print('NO')
``` | instruction | 0 | 94,635 | 9 | 189,270 |
No | output | 1 | 94,635 | 9 | 189,271 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.