message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one β 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
Input
The first line contains one integer n (1 β€ n β€ 100) β the number of testcases.
The i-th of the following n lines contains one integer xi (1 β€ xi β€ 100) β the number of chicken chunks Ivan wants to eat.
Output
Print n lines, in i-th line output YES if Ivan can buy exactly xi chunks. Otherwise, print NO.
Example
Input
2
6
5
Output
YES
NO
Note
In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much.
Submitted Solution:
```
# your code goes here
t=int(input())
for i in range(t):
n=int(input())
if n%3== 0 :
print("YES")
elif n%3==1 :
if n//3 >= 2 :
print("YES")
else :
print("NO")
else :
if n%7==0 :
print("YES")
elif (n-17)%21==0 or (n-20)%21==0 or (n-23)%21==0 or (n-26)%21==0 or (n-29)%21==0 or (n-32)%21==0 :
print("YES")
else :
print("NO")
``` | instruction | 0 | 87,243 | 9 | 174,486 |
No | output | 1 | 87,243 | 9 | 174,487 |
Provide a correct Python 3 solution for this coding contest problem.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5 | instruction | 0 | 87,384 | 9 | 174,768 |
"Correct Solution:
```
import sys
from itertools import combinations
def solve(n, pairs):
survivors = {v: {v} for v in range(1, n + 1)}
for x, y in reversed(pairs):
for v, srv in survivors.copy().items():
if x in srv:
if y in srv:
del survivors[v]
else:
srv.add(y)
elif y in srv:
srv.add(x)
return sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2))
n, m = map(int, input().split())
pairs = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
print(solve(n, pairs))
``` | output | 1 | 87,384 | 9 | 174,769 |
Provide a correct Python 3 solution for this coding contest problem.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5 | instruction | 0 | 87,385 | 9 | 174,770 |
"Correct Solution:
```
n,m=map(int,input().split())
v=[[1 for i in range(n)] for i in range(n)]
for i in range(m):
x,y=map(int,input().split())
x-=1
y-=1
if v[x][y]:
v[x][y],v[y][x]=0,0
for j in range(n):
if v[x][j]==0:
v[j][y],v[y][j]=0,0
for j in range(n):
if v[y][j]==0:
v[j][x],v[x][j]=0,0
else:
for j in range(n):
v[j][x],v[x][j],v[j][y],v[y][j]=0,0,0,0
print((sum(map(sum,v))-sum([v[i][i] for i in range(n)]))//2)
``` | output | 1 | 87,385 | 9 | 174,771 |
Provide a correct Python 3 solution for this coding contest problem.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5 | instruction | 0 | 87,386 | 9 | 174,772 |
"Correct Solution:
```
def get_survivors(n, pairs):
survivors = {v: {v} for v in range(n)}
for x, y in reversed(pairs):
for v, srv in survivors.copy().items():
if x in srv:
if y in srv:
del survivors[v]
else:
srv.add(y)
elif y in srv:
srv.add(x)
return survivors
def solve(n, pairs):
survivors = get_survivors(n, pairs)
ans = 0
for u, su in survivors.items():
for v, sv in survivors.items():
if u >= v:
continue
if su.isdisjoint(sv):
ans += 1
return ans
n, m = map(int, input().split())
pairs = []
for _ in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
pairs.append((x, y))
print(solve(n, pairs))
``` | output | 1 | 87,386 | 9 | 174,773 |
Provide a correct Python 3 solution for this coding contest problem.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5 | instruction | 0 | 87,387 | 9 | 174,774 |
"Correct Solution:
```
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
eat=[]
for i in range(M):
x,y=map(int,input().split())
eat.append((x,y))
eat=eat[::-1]
turkey=[]
for i in range(1,N+1):
tempval=set([i])
tempid=set([])
for j in range(M):
x,y=eat[j]
if x in tempval and y in tempval:
break
elif x in tempval:
tempval.add(y)
tempid.add(j)
elif y in tempval:
tempval.add(x)
tempid.add(j)
else:
turkey.append([tempval,tempid])
ans=0
n=len(turkey)
#print(turkey)
for i in range(1,n):
for j in range(i):
aval,aid=turkey[i]
bval,bid=turkey[j]
checkval=True
checkid=True
for val in bval:
checkval=checkval&(val not in aval)
for id in bid:
checkid=checkid&(id not in aid)
if checkid and checkval:
ans+=1
#print(i,j)
print(ans)
``` | output | 1 | 87,387 | 9 | 174,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5
Submitted Solution:
```
import sys
from itertools import combinations
n, m = map(int, input().split())
survivors = {v: {v + 1} for v in range(n)}
for x, y in reversed(map(int, line.split()) for line in sys.stdin.readlines()):
for v, srv in survivors.copy().items():
if x in srv:
if y in srv:
del survivors[v]
else:
srv.add(y)
elif y in srv:
srv.add(x)
print(sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2)))
``` | instruction | 0 | 87,388 | 9 | 174,776 |
No | output | 1 | 87,388 | 9 | 174,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5
Submitted Solution:
```
import sys
from itertools import combinations
def solve(n, pairs):
have_to_survive = [{v} for v in range(1, n + 1)]
survivors = [True] * n
for x, y in reversed(pairs):
for i, srv in enumerate(survivors):
if not srv:
continue
hts = have_to_survive[i]
if x in hts:
if y in hts:
survivors[i] = False
else:
hts.add(y)
elif y in hts:
hts.add(x)
finalists = [hts for srv, hts in zip(survivors, have_to_survive) if srv]
return sum(su.isdisjoint(sv) for su, sv in combinations(finalists, 2))
n, m = map(int, input().split())
pairs = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
print(solve(n, pairs))
``` | instruction | 0 | 87,389 | 9 | 174,778 |
No | output | 1 | 87,389 | 9 | 174,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5
Submitted Solution:
```
import sys
from itertools import combinations
n, m = map(int, input().split())
survivors = {v: {v + 1} for v in range(n)}
for x, y in reversed(list(map(int, line.split()) for line in sys.stdin.readlines())):
for v, srv in survivors.copy().items():
if x in srv:
if y in srv:
del survivors[v]
else:
srv.add(y)
elif y in srv:
srv.add(x)
print(sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2)))
``` | instruction | 0 | 87,390 | 9 | 174,780 |
No | output | 1 | 87,390 | 9 | 174,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N turkeys. We number them from 1 through N.
M men will visit here one by one. The i-th man to visit will take the following action:
* If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it.
* If either turkey x_i or y_i is alive (but not both): eats the alive one.
* If neither turkey x_i nor y_i is alive: does nothing.
Find the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the following condition is held:
* The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.
Constraints
* 2 β€ N β€ 400
* 1 β€ M β€ 10^5
* 1 β€ x_i < y_i β€ N
Input
Input is given from Standard Input in the following format:
N M
x_1 y_1
x_2 y_2
:
x_M y_M
Output
Print the number of pairs (i,\ j) (1 β€ i < j β€ N) such that the condition is held.
Examples
Input
3 1
1 2
Output
2
Input
4 3
1 2
3 4
2 3
Output
1
Input
3 2
1 2
1 2
Output
0
Input
10 10
8 9
2 8
4 6
4 9
7 8
2 8
1 8
3 4
3 4
2 7
Output
5
Submitted Solution:
```
def get_survivors(n, pairs):
survivors = {v: {v} for v in range(n)}
for x, y in reversed(pairs):
for v, srv in survivors.copy().items():
if x in srv:
if y in srv:
del survivors[v]
else:
srv.add(y)
elif y in srv:
srv.add(x)
return list(survivors.values())
def solve(n, pairs):
survivors = get_survivors(n, pairs)
ans = 0
for i, su in enumerate(survivors):
for sv in survivors[i + 1:]:
if su.isdisjoint(sv):
ans += 1
return ans
n, m = map(int, input().split())
pairs = []
for _ in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
pairs.append((x, y))
print(solve(n, pairs))
``` | instruction | 0 | 87,391 | 9 | 174,782 |
No | output | 1 | 87,391 | 9 | 174,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,000 | 9 | 176,000 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n, x = map(int,input().split())
c = 0
for i in range(n):
a, b = input().split()
b = int(b)
if a == '+':
x += b
else:
if x<b:
c+=1
else:
x-=b
print(x,c)
``` | output | 1 | 88,000 | 9 | 176,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,001 | 9 | 176,002 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,x=(int(i) for i in input().split())
dis=0
ice=x
for i in range(n):
a,b=(input().split())
b=int(b)
if (a=='+'):
ice+=b
else:
if (b>ice):
dis+=1
else:
ice-=b
print("{} {}".format(ice,dis))
``` | output | 1 | 88,001 | 9 | 176,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,002 | 9 | 176,004 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
def solve() :
n,x = map(int,input().split())
ini = x
dis = 0
for i in range(n) :
q = input()
if q[0]=="+" :
ini = ini + int(q[2:])
elif q[0]=="-" :
if ini>=int(q[2:]) :
ini = ini - int(q[2:])
else :
dis = dis + 1
print(ini,dis)
def main():
solve()
# region fastio
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__":
main()
``` | output | 1 | 88,002 | 9 | 176,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,003 | 9 | 176,006 |
Tags: constructive algorithms, implementation
Correct Solution:
```
a, b = input().split(" ")
a = int(a)
b = int(b)
f=0
sum = 0
s=b
e=0
for i in range(a):
c,d = input().split(" ")
d = int(d)
if c == '+':
s += d
else:
if s-d<0:
f += 1
else:
s= s-d
print(s, f)
``` | output | 1 | 88,003 | 9 | 176,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,004 | 9 | 176,008 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,d=list(map(int,input().split()))
c=0
for i in range(n):
r,p=input().split()
if r=='+':
d+=int(p)
elif r=='-':
if int(p)<=d:
d-=int(p)
else:
c+=1
print(d,c)
``` | output | 1 | 88,004 | 9 | 176,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,005 | 9 | 176,010 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,x = map(int,input().split())
cnt = 0
for i in range(n):
s,d = input().split()
d = int(d)
if s == '+':
x += d
elif s == '-':
if x >= d :
x-=d
elif x<d:
cnt +=1
print(str(x) + " " + str(cnt))
``` | output | 1 | 88,005 | 9 | 176,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,006 | 9 | 176,012 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,x = [int(y) for y in input().split(' ')]
d = 0
for nn in range(n):
p,q = [y for y in input().split(' ')]
if p == '+': x += int(q)
else:
q = int(q)
if q > x: d += 1
else: x -= q
print(x,d)
``` | output | 1 | 88,006 | 9 | 176,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining. | instruction | 0 | 88,007 | 9 | 176,014 |
Tags: constructive algorithms, implementation
Correct Solution:
```
a,Sum = map(int , input().split())
n=0
for i in range(a):
x,y = input().split()
if x == '+': Sum+=int(y)
else:
if Sum >= int(y):Sum-=int(y)
else :n+=1
print(Sum , n)
``` | output | 1 | 88,007 | 9 | 176,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
x = list(map(int,input().split()))
n = x[0]
ice = x[1]
temp = []
dis = 0
for i in range(n):
y=list(input().split())
temp.append(y)
for i in temp:
if i[0] == "-":
if int(i[1]) <= ice:
ice -= int(i[1])
else:
dis += 1
else:
ice += int(i[1])
print(str(ice)+" "+str(dis))
``` | instruction | 0 | 88,008 | 9 | 176,016 |
Yes | output | 1 | 88,008 | 9 | 176,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
n, x = (int(v) for v in input().split())
ans = 0
for _ in range(n):
inp = input().split()
val = int(inp[1])
sign = inp[0]
if sign == '+':
x += val
else:
if x < val:
ans += 1
else:
x -= val
print(x, ans)
``` | instruction | 0 | 88,009 | 9 | 176,018 |
Yes | output | 1 | 88,009 | 9 | 176,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
n, sum_ = map(int, input().split())
cnt = 0
for i in range(n):
op, d = input().split()
d = int(d)
sum_ += d if op == "+" else -d
if sum_ < 0:
cnt += 1
sum_ += d
print(f"{sum_} {cnt}")
``` | instruction | 0 | 88,010 | 9 | 176,020 |
Yes | output | 1 | 88,010 | 9 | 176,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
q, x = map(int, (input().split()))
sad_child = 0
for _ in range(q):
n = int(input().replace(' ', ''))
if n >= 0:
x += n
# print(x)
elif n < 0 and x >= abs(n):
x -= abs(n)
# print(x)
elif n < 0 and x < abs(n):
sad_child += 1
# print(x)
print(x, sad_child)
``` | instruction | 0 | 88,011 | 9 | 176,022 |
Yes | output | 1 | 88,011 | 9 | 176,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
n, x = map(int,input().split(' '))
n = int(n)
x = int(x)
icVal = x
dCount = 0
while n > 0:
a, b = input().split(' ')
b = int(b)
if a == '-':
b = b * -1
if (icVal + b) > 0:
icVal = icVal + b
else:
dCount = dCount + 1
n = n - 1
print(str(icVal) + " " + str(dCount))
``` | instruction | 0 | 88,012 | 9 | 176,024 |
No | output | 1 | 88,012 | 9 | 176,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
n,d=[int(i) for i in input().split()]
for i in range(n):
y=0
x=input().split()
if x[0]=='+':
p=int(x[1])
d=d+p
else:
p=int(x[1])
if d>=p:
d=d-p
else:
y=y+1
print(d,y)
``` | instruction | 0 | 88,013 | 9 | 176,026 |
No | output | 1 | 88,013 | 9 | 176,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
#http://codeforces.com/problemset/problem/686/A
inp = list(map(int,input().split()))
tCases = inp[0]
iceCream = inp[1]
store = []
distress = 0
for x in range(tCases):
temp = list(input().split())
store.append(temp)
for x in store:
if x[0] == "-":
if int(x[1]) <iceCream:
iceCream -= int(x[1])
else:
distress += 1
else:
iceCream += int(x[1])
print(str(iceCream) + " " + str(distress))
``` | instruction | 0 | 88,014 | 9 | 176,028 |
No | output | 1 | 88,014 | 9 | 176,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 β€ n β€ 1000, 0 β€ x β€ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 β€ di β€ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers β number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Submitted Solution:
```
n,x=[int(i) for i in input().split(" ")]
distress=0
for i in range(n):
query=input()
if query[0]=="+":
x+=int(query[2])
elif query[0]=="-":
if x-int(query[2])<0:
distress+=1
else:
x-=int(query[2])
print(x,distress)
``` | instruction | 0 | 88,015 | 9 | 176,030 |
No | output | 1 | 88,015 | 9 | 176,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES". | instruction | 0 | 88,067 | 9 | 176,134 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
a = sum(A)
b1, b2 = 0,0
for b in B:
if b > b1:
b2 = b1
b1 = b
elif b > b2:
b2 = b
if b1+b2 >= a:
print("YES")
else:
print("NO")
``` | output | 1 | 88,067 | 9 | 176,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES". | instruction | 0 | 88,068 | 9 | 176,136 |
Tags: greedy, implementation
Correct Solution:
```
a = int(input())
b = list(map(int,input().split()))
c = list(map(int,input().split()))
c.sort()
z = c[-1] +c[-2]
if sum(b)<=z:print("YES")
else:print("NO")
``` | output | 1 | 88,068 | 9 | 176,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES". | instruction | 0 | 88,069 | 9 | 176,138 |
Tags: greedy, implementation
Correct Solution:
```
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n = ii()
a = li()
b = li()
b.sort()
print('YES' if sum(a) <= b[-1] + b[-2] else 'NO')
``` | output | 1 | 88,069 | 9 | 176,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES". | instruction | 0 | 88,070 | 9 | 176,140 |
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.sort(reverse=True)
c=b[0]+b[1]
if c>=sum(a):
print("YES")
else:
print("NO")
``` | output | 1 | 88,070 | 9 | 176,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES". | instruction | 0 | 88,073 | 9 | 176,146 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
b.sort()
s = b[-1] + b[-2]
if sum(a) > s:
print('NO')
else:
print('YES')
``` | output | 1 | 88,073 | 9 | 176,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES". | instruction | 0 | 88,074 | 9 | 176,148 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if n == 2:
print("YES")
else:
tot = sum(a)
m1 = max(b)
b.remove(m1)
m2 = max(b)
if tot > m1+m2:
print("NO")
else:
print("YES")
``` | output | 1 | 88,074 | 9 | 176,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai β€ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input
The first line of the input contains one integer n (2 β€ n β€ 100 000) β number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai β€ bi β€ 109) β capacities of the cans.
Output
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is "YES".
Submitted Solution:
```
def greedy(lst1, lst2):
s = sum(lst1)
if s <= lst2[len(lst1) - 1] + lst2[len(lst1) - 2]:
return "YES"
return "NO"
n = int(input())
a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
print(greedy(a, b))
``` | instruction | 0 | 88,079 | 9 | 176,158 |
No | output | 1 | 88,079 | 9 | 176,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,750 | 9 | 177,500 |
Tags: dp
Correct Solution:
```
from collections import defaultdict
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
dp = [defaultdict(lambda : int(-2e9)) for _ in range(n+1)]
dp[0][n*100] = 0
for i in range(1, n+1):
s = a[i] - b[i] * k
for j in range(n*200, -1, -1):
dp[i][j] = max(dp[i-1][j], dp[i-1][j-s] + a[i])
print(dp[n][n*100] if dp[n][n*100] > 0 else -1)
``` | output | 1 | 88,750 | 9 | 177,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,751 | 9 | 177,502 |
Tags: dp
Correct Solution:
```
n, k = [int(x) for x in input().split(' ')]
taste = [int(x) for x in input().split(' ')]
cal = [int(x) for x in input().split(' ')]
w = [taste[i] - k*cal[i] for i in range(n)]
taste_per_diff = [-1 for i in range(50000)]
shift = 20000
taste_per_diff[shift] = 0
for i in range(n):
new_tpd = [x for x in taste_per_diff]
for j in range(0, 40000):
if taste_per_diff[j] != -1:
new_tpd[j+w[i]] = max(new_tpd[j+w[i]], taste_per_diff[j] + taste[i])
taste_per_diff = new_tpd
if taste_per_diff[shift] == 0:
print(-1)
else:
print(taste_per_diff[shift])
``` | output | 1 | 88,751 | 9 | 177,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,752 | 9 | 177,504 |
Tags: dp
Correct Solution:
```
k = int(input().split()[1])
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
ambk = [(a[i], a[i] - b[i]*k) for i in range(len(a))]
ambk.sort(key=lambda a:-a[1])
ts = [0]*(100*100)
keys = [0]
atras = range(100*100 -1, -1, -1)
adelante = range(100*100)
for i in range(len(a)):
for j in ( atras if ambk[i][1] >= 0 else adelante ):
if ts[j] > 0 or j == 0:
if j + ambk[i][1] >= 0:
ts[j+ambk[i][1]] = max(ts[j+ambk[i][1]], ts[j] + ambk[i][0])
print("-1" if ts[0] == 0 else str(ts[0]))
``` | output | 1 | 88,752 | 9 | 177,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,753 | 9 | 177,506 |
Tags: dp
Correct Solution:
```
from sys import stdin,stdout
Pi = lambda x: stdout.write(str(x) + '\n')
Ps = lambda x: stdout.write(str(x))
S = lambda x: x*(x+1) // 2
I = lambda x: 1+(2*x)
R = lambda:stdin.readline()
Ri = lambda x:map(int,x.split())
Rs = lambda x:map(str,x.split())
Rf = lambda x:map(float,x.split())
MaxN = int(1e5) + 10
# dp,A = []
def f(i,x,n,k,dp,A,B):
if i==n:
if x==0:return 0
return -1000000
if dp[i][x+MaxN]!=-1:return dp[i][x+MaxN]
op1 = f(i+1, x+A[i]-B[i]*k,n,k,dp,A,B)+A[i]
op2 = f(i+1, x,n,k,dp,A,B)
dp[i][x+MaxN] = max(op2,op1)
return dp[i][x+MaxN]
def main():
# t = int(R())
for x in stdin:
n,x = Ri(x)
A = list(Ri(R()))
B = list(Ri(R()))
dp = []
for i in range(110):
dp.append([-1]*(MaxN*2))
ans = f(0,0,n,x,dp,A,B)
if ans < 1:ans = -1
Pi(ans)
if __name__=='__main__':
main()
# 60 == 360
``` | output | 1 | 88,753 | 9 | 177,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,754 | 9 | 177,508 |
Tags: dp
Correct Solution:
```
[n,k] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
b.insert(0,0)
a.insert(0,0)
s = sum(b) * k
f = [[0 for i in range(0,4*s+1)] for j in range(0,n+1)]
for i in range(0,n+1):
a[i] = a[i] - (k * b[i])
for i in range(1,n+1):
for j in range(s,3*s+1):
f[i][j] = f[i-1][j]
if j-a[i] == 2*s or f[i-1][j-a[i]] > 0:
f[i][j] = max(f[i][j],f[i-1][j-a[i]]+b[i])
if f[n][2*s]:
print(f[n][2*s] * k)
else:
print(-1)
``` | output | 1 | 88,754 | 9 | 177,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,755 | 9 | 177,510 |
Tags: dp
Correct Solution:
```
n,k=map(int,input().split())
a=[int(temp) for temp in input().split()]#ε³ι
b=[int(temp) for temp in input().split()]#ε‘θ·―ιοΌε³ι/ε‘θ·―ι=k
c=[-a[i]+k*b[i] for i in range(n)]
lis={0:0}#θ΄ζ°
lis1={0:0}#ζ£ζ°
for i in range(n):
temp=lis.copy()
for j in list(lis.keys()):
if c[i]<0:
if j-c[i] in lis:
lis[j-c[i]]=max(temp[j-c[i]],temp[j]+a[i])
else :
lis[j-c[i]]=temp[j]+a[i]#θ΄ζ°θ£
θ½½
temp=list(lis)
temp.sort()
temp.reverse()
maxnum=temp[0]
for i in range(n):
temp1=lis1.copy()
for j in list(lis1.keys()):
if c[i]>=0:
if j+c[i] in lis1:
lis1[j+c[i]]=max(temp1[j+c[i]],temp1[j]+a[i])
elif j+c[i]<=maxnum:
lis1[j+c[i]]=temp1[j]+a[i]#ζ£ζ°θ£
θ½½
maxnum=0
for i in temp:
if i in lis1:
maxnum=max(lis[i]+lis1[i],maxnum)
if maxnum==0:
print(-1)
else:
print(maxnum)
# 78, 158, 0, 59, 1
#-31, -19,-20, -86, -2, -9, -14
``` | output | 1 | 88,755 | 9 | 177,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,756 | 9 | 177,512 |
Tags: dp
Correct Solution:
```
n, k = map(int, input().split())
x, y = [0] * 100001, [0] * 100001
x[0] = y[0] = 1
g = h = 0
for u, v in zip(*(map(int, input().split()), map(int, input().split()))):
d = u - k * v
if d > 0:
for j in range(g, -1, -1):
if x[j]: x[j + d] = max(x[j + d], x[j] + v)
g += d
else:
for j in range(h, -1, -1):
if y[j]: y[j - d] = max(y[j - d], y[j] + v)
h -= d
s = max(x[i] + y[i] for i in range(min(g, h) + 1) if x[i] and y[i]) - 2
print(k * s - (not s))
``` | output | 1 | 88,756 | 9 | 177,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle. | instruction | 0 | 88,757 | 9 | 177,514 |
Tags: dp
Correct Solution:
```
n,k=map(int,input().split())
s=list(map(int,input().split()))
s1=list(map(int,input().split()))
dp=[[[0 for j in range(10**5)] for l in range(2)] for i in range(n+1)]
y=s[0]-s1[0]*k
if y>=0:
dp[0][0][y]=s[0]
else:
dp[0][1][-y]=s[0]
for i in range(1,n):
y=s[i]-s1[i]*k
for j in range(100**2+2):
for l in range(2):
dp[i][l][j]=max(dp[i][l][j],dp[i-1][l][j])
if dp[i-1][l][j]!=0 or (j==0):
if l==1:
x=-j+y
else:
x=j+y
if x<0:
x=abs(x)
dp[i][1][x]=max(dp[i-1][1][x],dp[i][1][x],dp[i-1][l][j]+s[i])
else:
dp[i][0][x]=max(dp[i-1][0][x],dp[i][0][x],dp[i-1][l][j]+s[i])
if dp[n-1][0][0]==0:
print(-1)
else:
print(dp[n-1][0][0])
``` | output | 1 | 88,757 | 9 | 177,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(lambda x: int(x) * k, input().split()))
pos = [0] * 10 ** 5
neg = [0] * 10 ** 5
pos[0] = 1
neg[0] = 1
base = 0
for i in range(n):
d = a[i] - b[i]
if d > 0:
for j in range(10 ** 5-1,-1,-1):
if pos[j]:
if j + d < 10 ** 5:
pos[j+d] = max(pos[j+d],pos[j]+a[i])
elif d < 0:
for j in range(10 ** 5-1,-1,-1):
if neg[j]:
if j - d < 10 ** 5:
neg[j-d] = max(neg[j-d],neg[j]+a[i])
else:
base += a[i]
best = 0
for i in range(10 ** 5):
if pos[i] and neg[i]:
best = max(best,pos[i] + neg[i])
best -= 2
best += base
if best:
print(best)
else:
print(-1)
``` | instruction | 0 | 88,758 | 9 | 177,516 |
Yes | output | 1 | 88,758 | 9 | 177,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
diff = []
for x in range(n):
diff.append(a[x]-b[x]*k)
totals = {0:0}
for x in range(n):
t = a[x]
d = diff[x]
newGuys = []
for y in totals:
newGuys.append((y+d,totals[y] + t))
for y,z in newGuys:
if y in totals:
totals[y] = max(totals[y], z)
else:
totals[y] = z
if totals[0] == 0:
print(-1)
else:
print(totals[0])
if totals[0] == 1435:
print(' '.join([str(x) for x in diff]))
``` | instruction | 0 | 88,759 | 9 | 177,518 |
Yes | output | 1 | 88,759 | 9 | 177,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
n, k = [int(x) for x in input().split(' ')]
taste = [int(x) for x in input().split(' ')]
cal = [int(x) for x in input().split(' ')]
d = [[0 for j in range(10000*2)] for i in range(n)]
a = taste
b = cal
w = [a[i] - k*b[i] for i in range(n)]
dp = [-9999999 for i in range(300005)]
dp[10000] = 0
for i in range(n):
if w[i] > 0:
for j in range(20000, w[i], -1):
if dp[j - w[i]] != -9999999:
dp[j] = max(dp[j], dp[j-w[i]]+a[i])
else:
for j in range(20000):
if dp[j - w[i]] != -9999999:
dp[j] = max(dp[j], dp[j-w[i]]+a[i])
if dp[10000] == 0:
print(-1)
else:
print(dp[10000])
``` | instruction | 0 | 88,760 | 9 | 177,520 |
Yes | output | 1 | 88,760 | 9 | 177,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
from bisect import bisect_right
n, k = map(int, input().split())
t = sorted((u - k * v, v) for u, v in zip(*(map(int, input().split()), map(int, input().split()))))
m = n - bisect_right(t, (0, 0))
l, p, t = 0, [0] * 100001, t[:: -1]
for d, v in t[: m]:
for j in range(l, 0, -1):
if p[j]: p[j + d] = max(p[j + d], p[j] + v)
p[d] = max(p[d], p[0] + v)
l += d
for d, v in t[m: ]:
for j in range(- d, l + 1):
if p[j]: p[j + d] = max(p[j + d], p[j] + v)
print(p[0] * k if p[0] else -1)
``` | instruction | 0 | 88,761 | 9 | 177,522 |
Yes | output | 1 | 88,761 | 9 | 177,523 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
n,k=in_arr()
l1=in_arr()
l2=[i*k for i in in_arr()]
d=Counter()
d[0]=0
for i in range(n):
x=l1[i]-l2[i]
for j,k in d.items():
d[j+x]=max(d[j+x],k+l1[i])
pr_num(-1*(d[0]==0) + d[0])
``` | instruction | 0 | 88,762 | 9 | 177,524 |
Yes | output | 1 | 88,762 | 9 | 177,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
k = int(input().split()[1])
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
ambk = [(a[i], a[i] - b[i]*k) for i in range(len(a))]
ambk.sort(key=lambda a:-a[1])
print(str(ambk))
ts = [0]*(100*100)
keys = [0]
for i in range(len(a)):
for j in keys:
nk = set()
if j + ambk[i][1] >= 0:
if j + ambk[i][1] > 0 and ts[j + ambk[i][1]] == 0:
nk.add(j + ambk[i][1])
ts[j+ambk[i][1]] = max(ts[j+ambk[i][1]], ts[j] + ambk[i][0])
keys += list(nk)
print("-1" if ts[0] == 0 else str(ts[0]))
``` | instruction | 0 | 88,763 | 9 | 177,526 |
No | output | 1 | 88,763 | 9 | 177,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
[n,k] = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
w = [int(x) for x in input().split()]
a.insert(0,0)
w.insert(0,0)
s = sum(w)
q = 0
f = [[0 for y in range(0, s + 1)] for x in range(0, n + 1)]
for j in range(1,s+1):
f[0][j] = -999999
for i in range(1,n+1):
f[i][0] = 0
for i in range(1,n+1):
for j in range(1,s+1):
if w[i] <= j:
f[i][j] = max(f[i-1][j] , f[i-1][j-w[i]] + a[i])
if f[i][j] == k * j:
q = max(f[i][j],q)
else:
f[i][j] = f[i-1][j]
if q == 0:
print(-1)
else:
print(q)
``` | instruction | 0 | 88,764 | 9 | 177,528 |
No | output | 1 | 88,764 | 9 | 177,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
from collections import defaultdict
n, k = map(int, input().split())
a, b = list(map(int, input().split())), list(map(int, input().split()))
t, s = {0}, defaultdict(int)
for i in range(n):
u, v = a[i], b[i]
d = u - k * v
if d:
p = sorted(t, reverse = True)
q = [j + d for j in p]
for x, y in zip(*(p, q)): s[y] = max(s[y], s[x] + u)
t.update(q)
else:
for x in t: s[x] += u
print(s[0] if s[0] else -1)
``` | instruction | 0 | 88,765 | 9 | 177,530 |
No | output | 1 | 88,765 | 9 | 177,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, <image> , where aj is the taste of the j-th chosen fruit and bj is its calories.
Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem β now the happiness of a young couple is in your hands!
Inna loves Dima very much so she wants to make the salad from at least one fruit.
Input
The first line of the input contains two integers n, k (1 β€ n β€ 100, 1 β€ k β€ 10). The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 100) β the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 β€ bi β€ 100) β the fruits' calories. Fruit number i has taste ai and calories bi.
Output
If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer β the maximum possible sum of the taste values of the chosen fruits.
Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
Note
In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition <image> fulfills, that's exactly what Inna wants.
In the second test sample we cannot choose the fruits so as to follow Inna's principle.
Submitted Solution:
```
[n,k] = [int(x) for x in input().split()]
[a,b] = [[int(x) for x in input().split()] for i in range(0,2)]
f = [[0 for j in range(0,n+1)]for i in range(0,n+1)]
g = [[0 for j in range(0,n+1)]for i in range(0,n+1)]
for i in range(1,n+1):
f[i][i] = a[i-1]
g[i][i] = b[i-1]
q = 0
for i in range(1,n+1):
for j in range(i,n+1):
f[i][j] = f[i][j-1] + f[j][j]
g[i][j] = g[i][j-1] + g[j][j]
if float(int(f[i][j]) / int(g[i][j])) == float(k):
p = int(f[i][j])
q = max(q,p)
if q == 0:
print(-1)
else:
print(q)
``` | instruction | 0 | 88,766 | 9 | 177,532 |
No | output | 1 | 88,766 | 9 | 177,533 |
Provide a correct Python 3 solution for this coding contest problem.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 β€ i β€ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
* For each of the N kinds of doughnuts, make at least one doughnut of that kind.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
Constraints
* 2 β€ N β€ 100
* 1 β€ m_i β€ 1000
* m_1 + m_2 + ... + m_N β€ X β€ 10^5
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
m_1
m_2
:
m_N
Output
Print the maximum number of doughnuts that can be made under the condition.
Examples
Input
3 1000
120
100
140
Output
9
Input
4 360
90
90
90
90
Output
4
Input
5 3000
150
130
150
130
110
Output
26 | instruction | 0 | 89,078 | 9 | 178,156 |
"Correct Solution:
```
n,x = map(int, input().split())
a = [int(input()) for i in range(n)]
print((x-sum(a))//min(a) + n)
``` | output | 1 | 89,078 | 9 | 178,157 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.