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.
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.
The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.
The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.
Output
Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.
Examples
Input
5
2 7 3 4 9
3
1 25 11
Output
1
5
3
Note
For the sample input:
* The worms with labels from [1, 2] are in the first pile.
* The worms with labels from [3, 9] are in the second pile.
* The worms with labels from [10, 12] are in the third pile.
* The worms with labels from [13, 16] are in the fourth pile.
* The worms with labels from [17, 25] are in the fifth pile.
Submitted Solution:
```
n = int(input())
sp = list(map(int, input().split()))
input()
for el in map(int, input().split()):
L = 0
R = n
while R - L > 1:
M = (R + L) // 2
if sum(sp[:M]) > el:
R = M
else:
L = M
print(R)
``` | instruction | 0 | 5,404 | 9 | 10,808 |
No | output | 1 | 5,404 | 9 | 10,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.
The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.
The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.
Output
Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.
Examples
Input
5
2 7 3 4 9
3
1 25 11
Output
1
5
3
Note
For the sample input:
* The worms with labels from [1, 2] are in the first pile.
* The worms with labels from [3, 9] are in the second pile.
* The worms with labels from [10, 12] are in the third pile.
* The worms with labels from [13, 16] are in the fourth pile.
* The worms with labels from [17, 25] are in the fifth pile.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
juicy = int(input())
num = list(map(int,input().split()))
b = num.copy()
num.sort()
dictionary = {}
temp = 0
j = 0
for i in range(len(a)):
if temp+a[i] < num[j]:
temp = temp+a[i]
else :
temp = temp+a[i]
while temp >= num[j]:
dictionary[num[j]] = i+1
if j < len(b)-1:
j = j+1
elif j == len(b)-1:
break
for i in range(len(b)):
print(dictionary[b[i]])
``` | instruction | 0 | 5,405 | 9 | 10,810 |
No | output | 1 | 5,405 | 9 | 10,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.
The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.
The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.
Output
Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.
Examples
Input
5
2 7 3 4 9
3
1 25 11
Output
1
5
3
Note
For the sample input:
* The worms with labels from [1, 2] are in the first pile.
* The worms with labels from [3, 9] are in the second pile.
* The worms with labels from [10, 12] are in the third pile.
* The worms with labels from [13, 16] are in the fourth pile.
* The worms with labels from [17, 25] are in the fifth pile.
Submitted Solution:
```
n = int(input())
an = [int(x) for x in input().split()]
an.insert(0,0)
m = int(input())
qn = [int(x) for x in input().split()]
sum = [0 for i in range(len(an))]
for i in range(1,len(sum)):
sum[i] = an[i] + sum[i - 1]
print(sum)
for q in qn:
for x in range(1, len(sum)):
if sum[x - 1] < q < sum[x] or q == sum[x]:
print(x)
break
``` | instruction | 0 | 5,406 | 9 | 10,812 |
No | output | 1 | 5,406 | 9 | 10,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,016 | 9 | 12,032 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
import sys
from collections import defaultdict
from io import BytesIO, IOBase
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
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
self.BUFSIZE = 4096
def read(self):
while True:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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 = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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:
self.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")
def get_int():
return int(input())
def get_ints():
return list(map(int, input().split(' ')))
def solve_e():
n = get_ints()
costs = [get_ints() for course in range(4)]
costs = [[(x, j) for j, x in enumerate(cost)] for cost in costs]
m = []
mismatch_graph = [defaultdict(set) for _ in range(3)]
for course_trans in range(3):
m.append(get_int())
for mismatch in range(m[-1]):
a, b = get_ints()
mismatch_graph[course_trans][b - 1].add(a - 1)
dp = [sorted(costs[0])]
for j in range(3):
tmp = []
for l in range(n[j + 1]):
k = 0
while k < n[j]:
if costs[j + 1][l][-1] in mismatch_graph[j] and dp[-1][k][-1] in mismatch_graph[j][costs[j + 1][l][-1]]:
k += 1
else:
break
if k == n[j]:
tmp.append((float('inf'), costs[j + 1][l][-1]))
else:
tmp.append((costs[j + 1][l][0] + dp[-1][k][0], costs[j + 1][l][-1]))
dp.append(sorted(tmp))
if min(dp[-1])[0] == float('inf'):
return - 1
else:
return min(dp[-1])[0]
print(solve_e())
``` | output | 1 | 6,016 | 9 | 12,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,017 | 9 | 12,034 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
def read_int():
return int(input())
def read_ints():
return map(int, input().split(' '))
INF = int(1e9)
n = list(read_ints())
a = [[] for _ in range(4)]
a[0] = list(read_ints())
a[1] = list(read_ints())
a[2] = list(read_ints())
a[3] = list(read_ints())
dp = [(a[0][i], i) for i in range(n[0])]
dp.sort()
for k in range(3):
m = read_int()
banned = [set() for _ in range(n[k + 1])]
for _ in range(m):
u, v = read_ints()
banned[v - 1].add(u - 1)
f = [INF] * n[k + 1]
for i in range(n[k + 1]):
for j in range(n[k]):
if dp[j][1] not in banned[i]:
f[i] = dp[j][0] + a[k + 1][i]
break
dp = [(f[i], i) for i in range(n[k + 1])]
dp.sort()
print(dp[0][0] if dp[0][0] < INF else -1)
``` | output | 1 | 6,017 | 9 | 12,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,018 | 9 | 12,036 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from math import inf,isinf
def some_random_function():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am writing
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def main():
n = list(map(int,input().split()))
cost = [list(map(int,input().split())) for _ in range(4)]
op = [[] for _ in range(3)]
for i in range(3):
for _ in range(int(input())):
op[i].append(tuple(map(int,input().split())))
for i in range(2,-1,-1):
band = [[] for _ in range(n[i+1]+1)]
for j in op[i]:
band[j[1]].append(j[0])
ke = sorted(range(n[i+1]),key=lambda xx:cost[i+1][xx])
z = min(cost[i+1])
cost1 = cost[i]
for k in range(len(cost1)):
cost1[k] += z
addi = [0]*n[i]
for ind,k in enumerate(ke):
for z in band[k+1]:
if addi[z-1] == ind and not isinf(cost1[z-1]):
cost1[z-1] -= cost[i+1][k]
cost1[z-1] += inf if ind==len(ke)-1 else cost[i+1][ke[ind+1]]
addi[z-1] = ind+1
mini = min(cost[0])
if isinf(mini):
print(-1)
else:
print(mini)
# Fast IO Region
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")
def some_random_function1():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am writing
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function2():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am writing
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function3():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am writing
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
def some_random_function4():
"""due to the fast IO template, my code gets caught in
plag check for no reason. That is why, I am writing
random functions"""
x = 10
x *= 100
i_dont_know = x
why_am_i_writing_this = x*x
print(i_dont_know)
print(why_am_i_writing_this)
if __name__=='__main__':
main()
``` | output | 1 | 6,018 | 9 | 12,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,019 | 9 | 12,038 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
import sys
from sys import stdin
n = list(map(int,stdin.readline().split()))
a = [list(map(int,stdin.readline().split())) for i in range(4)]
v = [set([]) for i in range(3)]
for i in range(3):
m = int(stdin.readline())
for j in range(m):
x,y = map(int,stdin.readline().split())
x -= 1
y -= 1
v[i].add( (x,y) )
dp = [[float("inf")] * len(a[i]) for i in range(4)]
dp[0] = a[0]
for i in range(1,4):
lai = [ (dp[i-1][j],j) for j in range(len(a[i-1])) ]
lai.sort()
remR = [i for i in range(len(a[i]))]
for cost,lv in lai:
nexR = []
for rv in remR:
if (lv,rv) not in v[i-1]:
#print (dp[i][rv] , cost , a[i][rv])
dp[i][rv] = cost + a[i][rv]
else:
nexR.append(rv)
remR = nexR
if len(remR) == 0:
break
ans = (min(dp[-1]))
if ans == float("inf"):
print (-1)
else:
print (ans)
``` | output | 1 | 6,019 | 9 | 12,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,020 | 9 | 12,040 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
from sys import stdin, stdout
n1, n2, n3, n4 = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
b = [int(x) for x in stdin.readline().split()]
c = [int(x) for x in stdin.readline().split()]
d = [int(x) for x in stdin.readline().split()]
a = [[i, a[i]] for i in range(n1)]
a.sort(key=lambda x:x[1])
m1 = int(stdin.readline())
bad_match = [set() for _ in range(n2)]
for _ in range(m1):
X, Y = [int(x) for x in stdin.readline().split()]
bad_match[Y-1].add(X-1)
B = [[i, 400000001] for i in range(n2)]
for Y in range(n2):
for candidate in a:
if not (candidate[0] in bad_match[Y]):
B[Y][1] = candidate[1] + b[Y]
break
B.sort(key=lambda x:x[1])
m2 = int(stdin.readline())
bad_match = [set() for _ in range(n3)]
for _ in range(m2):
X, Y = [int(x) for x in stdin.readline().split()]
bad_match[Y-1].add(X-1)
C = [[i, 400000001] for i in range(n3)]
for Y in range(n3):
for candidate in B:
if not (candidate[0] in bad_match[Y]):
C[Y][1] = candidate[1] + c[Y]
break
C.sort(key=lambda x:x[1])
m3 = int(stdin.readline())
bad_match = [set() for _ in range(n4)]
for _ in range(m3):
X, Y = [int(x) for x in stdin.readline().split()]
bad_match[Y-1].add(X-1)
D = [400000001]*n4
for Y in range(n4):
for candidate in C:
if not (candidate[0] in bad_match[Y]):
D[Y] = candidate[1] + d[Y]
break
minimum = min(D)
if minimum >= 400000001:
stdout.write(str(-1)+'\n')
else:
stdout.write(str(minimum)+'\n')
``` | output | 1 | 6,020 | 9 | 12,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,021 | 9 | 12,042 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
import sys
import bisect
from collections import defaultdict
from io import BytesIO, IOBase
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
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
self.BUFSIZE = 8192
def read(self):
while True:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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 = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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:
self.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")
def get_int():
return int(input())
def get_ints():
return list(map(int, input().split(' ')))
def get_int_grid(n):
return [get_ints() for _ in range(n)]
def get_str():
return input().split(' ')
def yes_no(b):
if b:
return "YES"
else:
return "NO"
def prefix_sums(a):
p = [0]
for x in a:
p.append(p[-1] + x)
return p
def solve_a():
n = get_int()
a = get_ints()
return n - a.count(min(a))
def solve_b():
n, k = get_ints()
if n % 2 == 0:
return (k - 1) % n + 1
else:
return ((k + (k - 1) // (n // 2)) - 1) % n + 1
def solve_c():
n = get_int()
ans = []
if n % 2 == 1:
for team in range(n):
ans.extend([(-1) ** i for i in range(n - team - 1)])
else:
for team in range(n):
ans.extend([(-1) ** i - int(i == 0 and team % 2 == 0) for i in range(n - team - 1)])
return ans
def solve_d():
c_vals = [5]
i = 5
while c_vals[-1] < 10 ** 9 + 1:
c_vals.append((i ** 2 - 1) // 2 + 1)
i += 2
t = get_int()
r = []
for _ in range(t):
n = get_int()
r.append(bisect.bisect_right(c_vals, n))
return r
def solve_e():
n = get_ints()
costs = [get_ints() for course in range(4)]
costs = [[(x, j) for j, x in enumerate(cost)] for cost in costs]
m = []
mismatch_graph = [defaultdict(set) for _ in range(3)]
for course_trans in range(3):
m.append(get_int())
for mismatch in range(m[-1]):
a, b = get_ints()
mismatch_graph[course_trans][b - 1].add(a - 1)
dp = [sorted(costs[0])]
for j in range(3):
tmp = []
for l in range(n[j + 1]):
k = 0
while k < n[j]:
if costs[j + 1][l][-1] in mismatch_graph[j] and dp[-1][k][-1] in mismatch_graph[j][costs[j + 1][l][-1]]:
k += 1
else:
break
if k == n[j]:
tmp.append((float('inf'), costs[j + 1][l][-1]))
else:
tmp.append((costs[j + 1][l][0] + dp[-1][k][0], costs[j + 1][l][-1]))
dp.append(sorted(tmp))
if min(dp[-1])[0] == float('inf'):
return - 1
else:
return min(dp[-1])[0]
print(solve_e())
``` | output | 1 | 6,021 | 9 | 12,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,022 | 9 | 12,044 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
from sys import stdin
def read_int():
return int(stdin.readline())
def read_ints():
return map(int, stdin.readline().split(' '))
INF = int(1e9)
n = list(read_ints())
a = [list(read_ints()) for _ in range(4)]
dp = [(a[0][i], i) for i in range(n[0])]
dp.sort()
#print(a)
for k in range(3):
m = read_int()
banned = [set() for _ in range(n[k + 1])]
for _ in range(m):
u, v = read_ints()
banned[v - 1].add(u - 1)
f = [INF] * n[k + 1]
for i in range(n[k + 1]):
for j in range(n[k]):
if dp[j][1] not in banned[i]:
f[i] = dp[j][0] + a[k + 1][i]
break
dp = [(f[i], i) for i in range(n[k + 1])]
#print(dp)
dp.sort()
print(dp[0][0] if dp[0][0] < INF else -1)
``` | output | 1 | 6,022 | 9 | 12,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner. | instruction | 0 | 6,023 | 9 | 12,046 |
Tags: brute force, data structures, graphs, greedy, implementation, sortings, two pointers
Correct Solution:
```
#!/usr/bin/python3.6
import sys
input = sys.stdin.readline
def encode(x, y):
return (x - 1 << 18) + y
n1, n2, n3, n4 = map(int, input().split())
a = [(int(item), i) for i, item in enumerate(input().split())]
b = [(int(item), i) for i, item in enumerate(input().split())]
c = [(int(item), i) for i, item in enumerate(input().split())]
d = [(int(item), i) for i, item in enumerate(input().split())]
a.sort()
b.sort()
c.sort()
d.sort()
m1 = int(input())
m1s = set()
for _ in range(m1):
x, y = map(int, input().split())
x -= 1; y -= 1
m1s.add(encode(x, y))
m2 = int(input())
m2s = set()
for _ in range(m2):
x, y = map(int, input().split())
x -= 1; y -= 1
m2s.add(encode(x, y))
m3 = int(input())
m3s = set()
for _ in range(m3):
x, y = map(int, input().split())
x -= 1; y -= 1
m3s.add(encode(x, y))
ab = []
for bb, ib in b:
for aa, ia in a:
if encode(ia, ib) in m1s:
continue
ab.append((aa + bb, ib))
break
if not ab:
print(-1); exit()
ab.sort()
bc = []
for cc, ic in c:
for aabb, ib in ab:
if encode(ib, ic) in m2s:
continue
bc.append((aabb + cc, ic))
break
if not bc:
print(-1); exit()
bc.sort()
cd = []
ans = 10**10
for dd, idd in d:
for bbcc, ic in bc:
if encode(ic, idd) in m3s:
continue
if bbcc + dd < ans:
ans = bbcc + dd
break
if ans == 10**10:
print(-1)
else:
print(ans)
``` | output | 1 | 6,023 | 9 | 12,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
mod = 1000000007
eps = 10**-9
inf = 10**15
def main():
import sys
input = sys.stdin.buffer.readline
def F(L, R, bad):
NL = len(L)
NR = len(R)
ret = [inf] * NR
L_sorted = [(l, i) for i, l in enumerate(L)]
L_sorted.sort(key=lambda x: x[0])
for i, r in enumerate(R):
for l, k in L_sorted:
if k * (NR+1) + i in bad:
continue
else:
ret[i] = l + r
break
return ret
N1, N2, N3, N4 = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
M1 = int(input())
if M1 == N1 * N2:
print(-1)
exit()
bad1 = set()
for _ in range(M1):
x, y = map(int, input().split())
x -= 1
y -= 1
bad1.add(x * (N2+1) + y)
M2 = int(input())
if M2 == N2 * N3:
print(-1)
exit()
bad2 = set()
for _ in range(M2):
x, y = map(int, input().split())
x -= 1
y -= 1
bad2.add(x * (N3 + 1) + y)
M3 = int(input())
if M3 == N3 * N4:
print(-1)
exit()
bad3 = set()
for _ in range(M3):
x, y = map(int, input().split())
x -= 1
y -= 1
bad3.add(y * (N3 + 1) + x)
L = F(A, B, bad1)
R = F(D, C, bad3)
ans = min(F(L, R, bad2))
if ans < inf:
print(ans)
else:
print(-1)
if __name__ == '__main__':
main()
``` | instruction | 0 | 6,024 | 9 | 12,048 |
Yes | output | 1 | 6,024 | 9 | 12,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
import sys
input = sys.stdin.readline
input()
INF = 10 ** 18
prev = list(map(int, input().split()))
As = [list(map(int, input().split())) for _ in range(3)]
for nex in As:
order = sorted(range(len(prev)), key=prev.__getitem__)
nadj = [set() for _ in range(len(nex))]
for _ in range(int(input())):
x, y = map(lambda s: int(s)-1, input().split())
nadj[y].add(x)
for i in range(len(nex)):
j = 0
while j < len(order) and order[j] in nadj[i]: j += 1
nex[i] = min(INF, nex[i] + (prev[order[j]] if j < len(order) else INF))
prev = nex
r = min(prev)
print(-1 if r == INF else r)
``` | instruction | 0 | 6,025 | 9 | 12,050 |
Yes | output | 1 | 6,025 | 9 | 12,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
import sys
input = sys.stdin.readline
from operator import itemgetter
n1,n2,n3,n4=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
D=list(map(int,input().split()))
AX=[(a,i) for i,a in enumerate(A)]
AX.sort(key=itemgetter(0))
DPB=[1<<60]*n2
m2=int(input())
BAN=[set() for i in range(n2)]
for i in range(m2):
x,y=map(int,input().split())
BAN[y-1].add(x-1)
for j in range(n2):
for a,i in AX:
if i in BAN[j]:
continue
else:
DPB[j]=a+B[j]
break
DPC=[1<<60]*n3
m3=int(input())
BAN=[set() for i in range(n3)]
for i in range(m3):
x,y=map(int,input().split())
BAN[y-1].add(x-1)
BX=[(a,i) for i,a in enumerate(DPB)]
BX.sort(key=itemgetter(0))
for j in range(n3):
for a,i in BX:
if i in BAN[j]:
continue
else:
DPC[j]=a+C[j]
break
DPD=[1<<60]*n4
m4=int(input())
BAN=[set() for i in range(n4)]
for i in range(m4):
x,y=map(int,input().split())
BAN[y-1].add(x-1)
CX=[(a,i) for i,a in enumerate(DPC)]
CX.sort(key=itemgetter(0))
for j in range(n4):
for a,i in CX:
if i in BAN[j]:
continue
else:
DPD[j]=a+D[j]
break
ANS=min(DPD)
if ANS>=1<<60:
print(-1)
else:
print(ANS)
``` | instruction | 0 | 6,026 | 9 | 12,052 |
Yes | output | 1 | 6,026 | 9 | 12,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
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
self.BUFSIZE = 8192
def read(self):
while True:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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 = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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:
self.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")
def get_int():
return int(input())
def get_ints():
return list(map(int, input().split(' ')))
def get_int_grid(n):
return [get_ints() for _ in range(n)]
def get_str():
return input().split(' ')
def yes_no(b):
if b:
return "YES"
else:
return "NO"
def prefix_sums(a):
p = [0]
for x in a:
p.append(p[-1] + x)
return p
def solve_a():
n = get_int()
a = get_ints()
return n - a.count(min(a))
def solve_b():
n, k = get_ints()
if n % 2 == 0:
return (k - 1) % n + 1
else:
return ((k + (k - 1) // (n // 2)) - 1) % n + 1
def solve_c():
n = get_int()
ans = []
if n % 2 == 1:
for team in range(n):
ans.extend([(-1) ** i for i in range(n - team - 1)])
else:
for team in range(n):
ans.extend([(-1) ** i - int(i == 0 and team % 2 == 0) for i in range(n - team - 1)])
return ans
d_sols = [5]
i = 5
while d_sols[-1] < 10 ** 9 + 1:
d_sols.append((i ** 2 - 1) // 2 + 1)
i += 2
def solve_d():
n = get_int()
ans = bisect.bisect_right(d_sols, n)
return ans
def solve_e():
n = get_ints()
costs = [get_ints() for course in range(4)]
costs = [sorted([(x, j) for j, x in enumerate(cost)]) for cost in costs]
m = []
mismatch_graph = [defaultdict(set) for _ in range(3)]
for course_trans in range(3):
m.append(get_int())
for mismatch in range(m[-1]):
a, b = get_ints()
mismatch_graph[course_trans][b - 1].add(a - 1)
dp = [costs[0]]
for j in range(3):
tmp = []
for l in range(n[j + 1]):
k = 0
while k < n[j]:
if costs[j + 1][l][-1] in mismatch_graph[j] and dp[-1][k][-1] in mismatch_graph[j][costs[j + 1][l][-1]]:
k += 1
else:
break
if k == n[j]:
tmp.append((float('inf'), costs[j + 1][l][-1]))
else:
tmp.append((costs[j + 1][l][0] + dp[-1][k][0], costs[j + 1][l][-1]))
tmp.sort()
dp.append(tmp)
if min(dp[-1])[0] == float('inf'):
return - 1
else:
return min(dp[-1])[0]
print(solve_e())
``` | instruction | 0 | 6,027 | 9 | 12,054 |
Yes | output | 1 | 6,027 | 9 | 12,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
#i'm n..not ba.. b..baka > <
import sys
n = [int(i) for i in input().split()]
a = [[], [], [], [], ]
new_pos = []
for i in range(4):
tmp_list = [int(x) for x in input().split()]
new_pos.append([0, ] * n[i])
for j in range(n[i]):
a[i].append([tmp_list[j], j])
def upd_pos(i):
a[i].sort()
for j in range(n[i]):
new_pos[i][a[i][j][1]] = j
m = []
conf = [[], [], [], ]
conf_num = [[], [], [], ]
rev_conf_num = [[-1] * n[0], [-1] * n[1], [-1] * n[2], ]
def upd_conf(i):
tmp_list = []
for j in range(m[i]):
tmp_list.append([conf[i][j][0], new_pos[i + 1][conf[i][j][1]]])
conf[i] = []
tmp_list.sort()
tmp_list.append([96969696, 0])
r = 0
for j in range(0, m[i] + 1):
if(j != m[i] and rev_conf_num[i][tmp_list[j][0]] != -1):
continue
if (j == 0 or tmp_list[j][0] != tmp_list[j-1][0]):
if tmp_list[j][1] != 0:
continue
if j > 0 and len(conf_num[i]):
rev_conf_num[i][conf_num[i][-1]] = len(conf[i])
conf[i].append(r)
r = 0
conf_num[i].append(tmp_list[j][0])
else:
if(tmp_list[j][1] != tmp_list[j-1][1] + 1):
rev_conf_num[i][tmp_list[j][0]] = len(conf[i])
else:
r += 1
def upd_val(i):
for j in range(n[i]):
try:
if(rev_conf_num[i][j] != -1 and conf[i][rev_conf_num[i][j]] == n[i + 1] - 1) :
print("oh shit")
except IndexError:
print("oh shit\n"*10)
if (rev_conf_num[i][j] == -1):
val = a[i + 1][0][0]
elif conf[i][rev_conf_num[i][j]] == n[i + 1] - 1:
val = 999999999999
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
print("oh shit")
else:
val = a[i + 1][conf[i][rev_conf_num[i][j]] + 1][0]
a[i][j][0] += val
for i in range(3):
m.append(int(input()))
for j in range(m[i]):
conf[i].append([int(x) - 1 for x in input().split()])
for i in range(2,-1,-1):
upd_pos(i + 1)
upd_conf(i)
upd_val(i)
upd_pos(0)
print(a[0][0][0] if a[0][0][0] < 999999999999 else -1)
``` | instruction | 0 | 6,028 | 9 | 12,056 |
No | output | 1 | 6,028 | 9 | 12,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
INF = 10**18
def main():
n1, n2, n3, n4 = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
A = [(e, i) for i, e in enumerate(A)]
B = [(e, i) for i, e in enumerate(B)]
C = [(e, i) for i, e in enumerate(C)]
D = [(e, i) for i, e in enumerate(D)]
A.sort()
B.sort()
C.sort()
D.sort()
m1 = int(input())
XY1 = []
for i in range(m1):
x, y = map(int, input().split())
x, y = x-1, y-1
XY1.append((x,y))
m2 = int(input())
XY2 = []
for i in range(m2):
x, y = map(int, input().split())
x, y = x-1, y-1
XY2.append((x,y))
m3 = int(input())
XY3 = []
for i in range(m3):
x, y = map(int, input().split())
x, y = x-1, y-1
XY3.append((x,y))
N = n1+n2+n3+n4+2
g = [[] for i in range(N)]
for a, i in A:
g[N-2].append((a, i))
# 1-2
S1 = set(range(n1))
XY1 = set(XY1)
for b, i in B:
used = set()
for j in S1:
if (j, i) in XY1:
continue
g[j].append((b, i+n1))
used.add(j)
for j in used:
S1.remove(j)
if not S1:
break
S2 = set(range(n2))
for a, i in A:
used = set()
for j in S2:
if (i, j) in XY1:
continue
g[i].append((B[j][0], j+n1))
used.add(j)
for j in used:
S2.remove(j)
# 2-3
S2 = set(range(n2))
XY2 = set(XY2)
for c, i in C:
used = set()
for j in S2:
if (j, i) in XY2:
continue
g[j+n1].append((c, i+n1+n2))
used.add(j)
for j in used:
S2.remove(j)
S3 = set(range(n3))
for b, i in B:
used = set()
for j in S3:
if (i, j) in XY2:
continue
g[i+n1].append((C[j][0], j+n1+n2))
used.add(j)
for j in used:
S3.remove(j)
# 3-4
S3 = set(range(n3))
XY3 = set(XY3)
for d, i in D:
used = set()
for j in S3:
if (j, i) in XY3:
continue
g[j+n1+n2].append((d, i+n1+n2+n3))
used.add(j)
for j in used:
S3.remove(j)
S4 = set(range(n4))
XY3 = set(XY3)
for c, i in C:
used = set()
for j in S4:
if (i, j) in XY3:
continue
g[i+n1+n2].append((D[j][0], j+n1+n2+n3))
used.add(j)
for j in used:
S4.remove(j)
for i in range(n4):
g[i+n1+n2+n3].append((0, N-1))
import heapq
def dijkstra_heap(s, edge):
n = len(edge)
d = [INF] * n
used = [True] * n #True: not used
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,(e[0]+d[v],e[1]))
return d
d = dijkstra_heap(N-2, g)
#print(d)
if d[N-1] != INF:
print(d[N-1])
else:
print(-1)
if __name__ == '__main__':
main()
``` | instruction | 0 | 6,029 | 9 | 12,058 |
No | output | 1 | 6,029 | 9 | 12,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
"""
Author - Satwik Tiwari .
7th Feb , 2021 - Sunday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil,sqrt,log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O region
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def testcase(t):
for pp in range(t):
solve(pp)
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
y%=(p-1) #not so sure about this. used when y>p-1. if p is prime.
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
inf = pow(10,20)
mod = 10**9+7
#===============================================================================================
# code here ;))
def bucketsort(order, seq):
buckets = [0] * (max(seq) + 1)
for x in seq:
buckets[x] += 1
for i in range(len(buckets) - 1):
buckets[i + 1] += buckets[i]
new_order = [-1] * len(seq)
for i in reversed(order):
x = seq[i]
idx = buckets[x] = buckets[x] - 1
new_order[idx] = i
return new_order
def ordersort(order, seq, reverse=False):
bit = max(seq).bit_length() >> 1
mask = (1 << bit) - 1
order = bucketsort(order, [x & mask for x in seq])
order = bucketsort(order, [x >> bit for x in seq])
if reverse:
order.reverse()
return order
def long_ordersort(order, seq):
order = ordersort(order, [int(i & 0x7fffffff) for i in seq])
return ordersort(order, [int(i >> 31) for i in seq])
def multikey_ordersort(order, *seqs, sort=ordersort):
for i in reversed(range(len(seqs))):
order = sort(order, seqs[i])
return order
def do(a,b,map):
ans = [-1]*len(b)
ind = [i for i in range(len(a))]
order = multikey_ordersort(range(len(a)),a,ind)
new = []
for i in order:
new.append((a[i],ind[i]))
for i in range(len(b)):
for j in range(len(a)):
if((new[j][1],i) in map): continue
ans[i] = b[i] + new[j][0]
break
return ans
def solve(case):
n1,n2,n3,n4 = sep()
a = lis()
b = lis()
c = lis()
d = lis()
map1 = {}
for i in range(int(inp())):
x,y = sep()
x-=1;y-=1
map1[(x,y)] = 1
map2 = {}
for i in range(int(inp())):
x,y = sep()
x-=1;y-=1
map2[(x,y)] = 1
map3 = {}
for i in range(int(inp())):
x,y = sep()
x-=1;y-=1
map3[(x,y)] = 1
dp = a
dp = do(dp,b,map1)
if(min(dp) <= 0):
print(-1)
return
dp = do(dp,c,map2)
if(min(dp) <= 0):
print(-1)
return
dp = do(dp,d,map3)
ans = min(dp)
if(ans <= 0): print(-1)
else: print(ans)
testcase(1)
# testcase(int(inp()))
``` | instruction | 0 | 6,030 | 9 | 12,060 |
No | output | 1 | 6,030 | 9 | 12,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to have a good dinner. A good dinner should consist of a first course, a second course, a drink, and a dessert.
There are n_1 different types of first courses Ivan can buy (the i-th of them costs a_i coins), n_2 different types of second courses (the i-th of them costs b_i coins), n_3 different types of drinks (the i-th of them costs c_i coins) and n_4 different types of desserts (the i-th of them costs d_i coins).
Some dishes don't go well with each other. There are m_1 pairs of first courses and second courses that don't go well with each other, m_2 pairs of second courses and drinks, and m_3 pairs of drinks and desserts that don't go well with each other.
Ivan wants to buy exactly one first course, one second course, one drink, and one dessert so that they go well with each other, and the total cost of the dinner is the minimum possible. Help him to find the cheapest dinner option!
Input
The first line contains four integers n_1, n_2, n_3 and n_4 (1 ≤ n_i ≤ 150000) — the number of types of first courses, second courses, drinks and desserts, respectively.
Then four lines follow. The first line contains n_1 integers a_1, a_2, ..., a_{n_1} (1 ≤ a_i ≤ 10^8), where a_i is the cost of the i-th type of first course. Three next lines denote the costs of second courses, drinks, and desserts in the same way (1 ≤ b_i, c_i, d_i ≤ 10^8).
The next line contains one integer m_1 (0 ≤ m_1 ≤ 200000) — the number of pairs of first and second courses that don't go well with each other. Each of the next m_1 lines contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) denoting that the first course number x_i doesn't go well with the second course number y_i. All these pairs are different.
The block of pairs of second dishes and drinks that don't go well with each other is given in the same format. The same for pairs of drinks and desserts that don't go well with each other (0 ≤ m_2, m_3 ≤ 200000).
Output
If it's impossible to choose a first course, a second course, a drink, and a dessert so that they go well with each other, print -1. Otherwise, print one integer — the minimum total cost of the dinner.
Examples
Input
4 3 2 1
1 2 3 4
5 6 7
8 9
10
2
1 2
1 1
2
3 1
3 2
1
1 1
Output
26
Input
1 1 1 1
1
1
1
1
1
1 1
0
0
Output
-1
Note
The best option in the first example is to take the first course 2, the second course 1, the drink 2 and the dessert 1.
In the second example, the only pair of the first course and the second course is bad, so it's impossible to have dinner.
Submitted Solution:
```
import io
import os
from collections import defaultdict
# https://raw.githubusercontent.com/cheran-senthil/PyRival/master/pyrival/data_structures/SegmentTree.py
class SegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size : _size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
"""func of data[start, stop)"""
start += self._size
stop += self._size
res_left = res_right = self._default
while start < stop:
if start & 1:
res_left = self._func(res_left, self.data[start])
start += 1
if stop & 1:
stop -= 1
res_right = self._func(self.data[stop], res_right)
start >>= 1
stop >>= 1
return self._func(res_left, res_right)
def __repr__(self):
return "SegmentTree({0})".format(self.data)
inf = float("inf")
def solve(A, B, C, D, M1, M2, M3):
def groupBadPrev(M):
d = defaultdict(list)
for x, y in M:
x -= 1
y -= 1
d[y].append(x)
return d
dp = list(A)
courses = [B, C, D]
badPrevs = [
groupBadPrev(M1),
groupBadPrev(M2),
groupBadPrev(M3),
]
for course, badPrev in zip(courses, badPrevs):
prevDp = dp
segTree = SegmentTree(prevDp, inf, min)
dp = [inf] * len(course)
bestA = segTree.query(0, len(segTree))
for b in range(len(course)):
if b in badPrev:
# Temporarily set unreachable prev to inf weight
for a in badPrev[b]:
segTree[a] = inf
# Extend off lowest
dp[b] = segTree.query(0, len(segTree)) + course[b]
# Undo
for a in badPrev[b]:
segTree[a] = prevDp[a]
else:
dp[b] = bestA + course[b]
ans = max(dp)
if ans == inf:
return -1
return ans
if __name__ == "__main__":
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = 1
for tc in range(1, TC + 1):
N1, N2, N3, N4 = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
D = [int(x) for x in input().split()]
(M,) = [int(x) for x in input().split()]
M1 = [[int(x) for x in input().split()] for i in range(M)]
(M,) = [int(x) for x in input().split()]
M2 = [[int(x) for x in input().split()] for i in range(M)]
(M,) = [int(x) for x in input().split()]
M3 = [[int(x) for x in input().split()] for i in range(M)]
ans = solve(A, B, C, D, M1, M2, M3)
print(ans)
``` | instruction | 0 | 6,031 | 9 | 12,062 |
No | output | 1 | 6,031 | 9 | 12,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked. | instruction | 0 | 6,207 | 9 | 12,414 |
Tags: implementation
Correct Solution:
```
alcho = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"]
t = int(input())
c = 0
for _ in range(t):
n = input()
if n.isdigit():
if int(n) < 18:
c += 1
else:
if n in alcho:
c += 1
print(c)
``` | output | 1 | 6,207 | 9 | 12,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
alcohol=['ABSINTH','BEER','BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
d=0
for _ in range(int(input())):
b=input()
if b.isnumeric()==True:
if int(b)<18:
d+=1
else:
if b in alcohol:
d+=1
print(d)
``` | instruction | 0 | 6,213 | 9 | 12,426 |
Yes | output | 1 | 6,213 | 9 | 12,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
n = int(input())
alc = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"]
cnt = 0
for i in range(n):
s = input()
if s in alc:
cnt+=1
if s.isnumeric() and int(s) < 18:
cnt+=1
print(cnt)
``` | instruction | 0 | 6,214 | 9 | 12,428 |
Yes | output | 1 | 6,214 | 9 | 12,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
a=int(input())
d=[]
count=0
b=0
for i in range(a):
c=input()
d.append(c)
for i in range(a):
try:
if (int(d[i])<18):
count=count+1
except:
if d[i] in ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']:
b=b+1
print(count+b)
``` | instruction | 0 | 6,216 | 9 | 12,432 |
Yes | output | 1 | 6,216 | 9 | 12,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
n=int(input())
bar=[ 'ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN','RUM','SAKE','TEQUILA','VODKA', 'WHISKEY', 'WINE']
d=[]
for i in range(n):
x=input()
d.append(x)
z=0
for drink in d:
if drink in bar:
z+=1
if drink<'18':
z+=1
print(z)
``` | instruction | 0 | 6,217 | 9 | 12,434 |
No | output | 1 | 6,217 | 9 | 12,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
x=['ABSINTH', 'BEER', 'BRANDY', ' CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
c=0
num='0123456789'
for _ in range(int(input())):
y=input()
if y[0] in num:
if int(y)<18:
c+=1
elif y in x:
c+=1
print(c)
``` | instruction | 0 | 6,218 | 9 | 12,436 |
No | output | 1 | 6,218 | 9 | 12,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
c=0
s=["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"]
n=int(input())
for i in range(n):
v=input()
if(v<"18"):
c+=1
else:
if(v in s):
c+=1
print(c)
``` | instruction | 0 | 6,219 | 9 | 12,438 |
No | output | 1 | 6,219 | 9 | 12,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input
The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Examples
Input
5
18
VODKA
COKE
19
17
Output
2
Note
In the sample test the second and fifth clients should be checked.
Submitted Solution:
```
forbid = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY".split(", ")
n = int(input())
a = []
for i in range(n):
x = input()
if x.isnumeric():
if int(x) < 18:
a.append(x)
if x.isalpha():
if x in forbid:
a.append(x)
print(len(a))
``` | instruction | 0 | 6,220 | 9 | 12,440 |
No | output | 1 | 6,220 | 9 | 12,441 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,397 | 9 | 12,794 |
"Correct Solution:
```
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (T+1) for _ in range(N+1)]
AB.sort()
ret = 0
for i in range(1,N+1):
for j in range(1,T+1):
if j < AB[i-1][0]:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = max(dp[i-1][j-AB[i-1][0]] + AB[i-1][1], dp[i-1][j])
m = 0
for i in range(N):
m = max(m, AB[i][1]+dp[i][T-1])
print(m)
``` | output | 1 | 6,397 | 9 | 12,795 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,398 | 9 | 12,796 |
"Correct Solution:
```
N,M=map(int,input().split())
AB=[]
for i in range(N):
AB.append(list(map(int,input().split())))
AB.sort(key=lambda x: x[0])
max_=0
for i in AB:
if max_<i[0]:
max_=i[0]
dp=[0]*(max_+M)
max_=0
for i in AB:
for j in range(M)[::-1]:
dp[j+i[0]] = max(dp[j+i[0]],dp[j]+i[1])
print(max(dp))
``` | output | 1 | 6,398 | 9 | 12,797 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,399 | 9 | 12,798 |
"Correct Solution:
```
n, W = map(int, input().split())
ab = [tuple(map(int, input().split()))for _ in range(n)]
ab.sort(reverse=True)
dp = [0]*W
for w, v in ab:
for j in reversed(range(W)):
if j-w < 0:
break
if dp[j] < dp[j-w]+v:
dp[j] = dp[j-w]+v
if dp[0] < v:
dp[0] = v
print(max(dp))
``` | output | 1 | 6,399 | 9 | 12,799 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,400 | 9 | 12,800 |
"Correct Solution:
```
N,T = map(int, input().split())
abl = []
for _ in range(N):
a,b = map(int, input().split())
abl.append((a,b))
abl.sort()
dp = [ [0]*6001 for _ in range(N+1) ]
for i in range(N):
a,b = abl[i]
for t in range(6001):
dp[i+1][t] = max(dp[i+1][t], dp[i][t])
if t < T: dp[i+1][t+a] = max(dp[i][t]+b, dp[i][t+a])
ans = max(dp[N])
print(ans)
``` | output | 1 | 6,400 | 9 | 12,801 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,401 | 9 | 12,802 |
"Correct Solution:
```
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
dp=[[0]*(t) for i in range(n+1)]
for i in range(1,n+1):
for j in range(t):
if j-l[i-1][0]>=0:
dp[i][j]=max(dp[i-1][j-l[i-1][0]]+l[i-1][1],dp[i-1][j])
else:
dp[i][j]=dp[i-1][j]
ans=[]
for i in range(n):
ans.append(dp[i][-1]+l[i][1])
print(max(ans))
``` | output | 1 | 6,401 | 9 | 12,803 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,402 | 9 | 12,804 |
"Correct Solution:
```
N, T = map(int, input().split())
a_list = []
for _ in range(N):
a, b = map(int, input().split())
a_list.append((a, b))
a_list.sort(key=lambda x: x[0])
dp = [[0 for _ in range(T + 3001)] for _ in range(N + 1)]
for i in range(1, N + 1):
a, b = a_list[i - 1]
for j in range(T + 3001):
dp[i][j] = dp[i - 1][j]
for j in range(T):
dp[i][j + a] = max(dp[i - 1][j + a], dp[i - 1][j] + b)
print(max(dp[-1]))
``` | output | 1 | 6,402 | 9 | 12,805 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,403 | 9 | 12,806 |
"Correct Solution:
```
n,t = map(int,input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
dp = [[0 for i in range(t+1)]for j in range(n+1)]
for i in range(n):
ti,vi = ab[i]
for j in range(t+1):
if j + ti <= t:
dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
dp[i+1][j] = max(dp[i][j],dp[i+1][j])
ans = 0
for i, (ti, vi) in enumerate(ab):
ans = max(ans, dp[i][t - 1] + vi)
print(ans)
``` | output | 1 | 6,403 | 9 | 12,807 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145 | instruction | 0 | 6,404 | 9 | 12,808 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
N,T=map(int,input().split())
D=[tuple(map(int,input().split())) for i in range(N)]
D.sort()
DP=[0]*(T+1)
ANS=0
for i in range(N):
a,b=D[i]
for j in range(T,a-1,-1):
DP[j]=max(DP[j-a]+b,DP[j])
for j in range(i+1,N):
ANS=max(ANS,DP[T-1]+D[j][1])
print(ANS)
``` | output | 1 | 6,404 | 9 | 12,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
def main():
N, T = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x: x[0])
t = ab[-1][0]
dp = [-1]*(T+t+1)
dp[0] = 0
for a, b in ab:
for i in range(T-1, -1, -1):
if dp[i] < 0:
continue
if dp[i+a] < dp[i]+b:
dp[i+a] = dp[i]+b
ans = max(dp)
print(ans)
main()
``` | instruction | 0 | 6,405 | 9 | 12,810 |
Yes | output | 1 | 6,405 | 9 | 12,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
n,t=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
ab.sort()
dp=[6007*[0]for _ in range(n)]
ans=0
for i in range(n):
a,b=ab[i]
for j in range(6007):
if i==0:
if j>=a and j<t:dp[i][j]=b
elif j>=a and j-a<t:dp[i][j]=max(dp[i-1][j-a]+b,dp[i-1][j])
else:dp[i][j]=dp[i-1][j]
ans=max(ans,dp[i][j])
print(ans)
``` | instruction | 0 | 6,406 | 9 | 12,812 |
Yes | output | 1 | 6,406 | 9 | 12,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
L=[]
for i in range(n):
L.append(l[i][1])
dp=[[0]*(t) for i in range(n+1)]
for i in range(1,n+1):
for j in range(t):
if j-l[i-1][0]>=0:
dp[i][j]=max(dp[i-1][j-l[i-1][0]]+l[i-1][1],dp[i-1][j])
else:
dp[i][j]=dp[i-1][j]
ans=[]
for i in range(n):
ans.append(dp[i][-1]+max(L[i:]))
print(max(ans))
``` | instruction | 0 | 6,407 | 9 | 12,814 |
Yes | output | 1 | 6,407 | 9 | 12,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
def main():
e=enumerate
(n,t),*g=[list(map(int,t.split()))for t in open(0)]
d=[0]
g.sort()
dp=[]
d=[0]*t
for a,b in g:
p=d[:]
for i in range(a,t):
v=d[i-a]+b
if v>p[i]:p[i]=v
dp+=p,
d=p
a=m=0
for(*_,v),(_,w)in zip(dp[-2::-1],g[::-1]):
if w>m:m=w
if v+m>a:a=v+m
print(a)
main()
``` | instruction | 0 | 6,408 | 9 | 12,816 |
Yes | output | 1 | 6,408 | 9 | 12,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
from operator import itemgetter
def cul(menu):
good = 0 # 美味しさ
time = 0 # 時間
for i in range(len(menu)):
if time >= T-1:
break
else:
good += menu[i][1]
time += menu[i][0]
return good
N,T = map(int,input().split())
menu = list()
for i in range(N):
menu.append(list(map(int,input().split())))
# 時間が少ない順に計算
menu.sort() # 時間が少ない順にソート
good_1 = cul(menu)
# 満足度が多い順に計算
menu.sort(key=itemgetter(1),reverse=True)
good_2 = cul(menu)
print(max(good_1,good_2))
# 満足度と時間を考えてソート
# menu_1 = dict()
# for i in range(len(menu)):
# if abs(menu[i][1]-menu[i][0]) not in menu_1:
# menu_1[abs(menu[i][1]-menu[i][0])] = menu[i]
# print(menu_1)
``` | instruction | 0 | 6,409 | 9 | 12,818 |
No | output | 1 | 6,409 | 9 | 12,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[[0] * T for _ in range(N + 1)] for _ in range(2)] # (最後の注文を使ったか, i未満までみた, T)
for i in range(1, N + 1):
a, b = AB[i-1]
for t in range(T):
if t-a>=0:
dp[0][i][t] = max(dp[0][i - 1][t], dp[0][i - 1][t-a] + b)
else:
dp[0][i][t] = dp[0][i - 1][t]
dp[1][i][t] = max(dp[1][i - 1][t], dp[0][i - 1][t] + b)
print(dp[1][N][T-1])
``` | instruction | 0 | 6,410 | 9 | 12,820 |
No | output | 1 | 6,410 | 9 | 12,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
N,T = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]
dp = [[[0,0] for t in range(T)] for i in range(N+1)]
for i,(a,b) in enumerate(AB):
for t in range(T-1,-1,-1):
dp[i+1][t][0] = max(dp[i+1][t][0], dp[i][t][0])
dp[i+1][t][1] = max(dp[i+1][t][1], dp[i][t][1])
if t+a < T:
dp[i+1][t+a][0] = max(dp[i+1][t+a][0], dp[i][t][0] + b)
dp[i+1][t+a][1] = max(dp[i+1][t+a][1], dp[i][t][1] + b)
dp[i+1][t][1] = max(dp[i+1][t][1], dp[i][t][0] + b)
print(dp[-1][-1][-1])
``` | instruction | 0 | 6,411 | 9 | 12,822 |
No | output | 1 | 6,411 | 9 | 12,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
* You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.
* You cannot order the same kind of dish more than once.
* Until you finish eating the dish already served, you cannot order a new dish.
* After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.
Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.
What is the maximum possible happiness achieved by making optimal choices?
Constraints
* 2 \leq N \leq 3000
* 1 \leq T \leq 3000
* 1 \leq A_i \leq 3000
* 1 \leq B_i \leq 3000
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T
A_1 B_1
:
A_N B_N
Output
Print the maximum possible happiness Takahashi can achieve.
Examples
Input
2 60
10 10
100 100
Output
110
Input
3 60
10 10
10 20
10 30
Output
60
Input
3 60
30 10
30 20
30 30
Output
50
Input
10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25
Output
145
Submitted Solution:
```
N, T = map(int, input().split())
data = []
for i in range(N):
a, b = map(int, input().split())
data.append((a,b))
data.sort()
#print(data)
dp = [0] * T
ans = 0
for a, b in data:
ans = max(ans, dp[-1]+b)
if a < T:
eatable = dp[:T-a]
j = 0
for i in range(a, T, 1):
if dp[i] < eatable[j] + b:
dp[i] = eatable[j] + b
j += 1
print(ans)
``` | instruction | 0 | 6,412 | 9 | 12,824 |
No | output | 1 | 6,412 | 9 | 12,825 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7 | instruction | 0 | 6,521 | 9 | 13,042 |
"Correct Solution:
```
# AOJ 0550: Dividing Snacks
# Python3 2018.7.1 bal4u
import sys
from sys import stdin
input = stdin.readline
INF = 0x7fffffff
n = int(input())
dp = [INF]*(n+1)
dp[0] = 0
for i in range(1, n):
t = int(input())
for j in range(1+(i>>1)):
if dp[j] > dp[i-j] + t: dp[j] = dp[i-j] + t;
if dp[i-j] > dp[j] + t: dp[i-j] = dp[j] + t
print(dp[n>>1])
``` | output | 1 | 6,521 | 9 | 13,043 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7 | instruction | 0 | 6,522 | 9 | 13,044 |
"Correct Solution:
```
n = int(input())
dp = [float('inf')]*(n+1)
dp[0] = 0
cost = [int(input()) for _ in range(n-1)]
for i in range(1,n):
for j in range(i):
if dp[i-j]+cost[i-1] < dp[j]: dp[j] = dp[i-j]+cost[i-1]# = min(dp[j],dp[i-j]+cost[i-1])
if dp[j]+cost[i-1] < dp[i-j]: dp[i-j] = dp[j]+cost[i-1]# = min(dp[i-j],dp[j]+cost[i-1])
#print(dp)
print(dp[n//2])
``` | output | 1 | 6,522 | 9 | 13,045 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7 | instruction | 0 | 6,523 | 9 | 13,046 |
"Correct Solution:
```
#お菓子
n = int(input())
times = [int(input()) for _ in range(n-1)]
dp = [10**20 for i in range(n+1)]
dp[0] = 0
for i in range(1,n):
for j in range(i):
if dp[j] > dp[i-j] + times[i-1]:
dp[j] = dp[i-j] + times[i-1]
if dp[i-j] > dp[j] + times[i-1]:
dp[i-j] = dp[j] + times[i-1]
print(dp[n//2])
``` | output | 1 | 6,523 | 9 | 13,047 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7 | instruction | 0 | 6,524 | 9 | 13,048 |
"Correct Solution:
```
dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
a=int(input())
for j in range(i//2+1):
if dp[j]>dp[i-j]+a:dp[j]=dp[i-j]+a
if dp[i-j]>dp[j]+a:dp[i-j]=dp[j]+a
print(dp[n//2])
``` | output | 1 | 6,524 | 9 | 13,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7
Submitted Solution:
```
INF = 100
n = int(input())
l = [0 if i == 0 else int(input()) for i in range(n)]
#dp = [[[INF] * 2 for i in range(n // 2 + 1)] for j in range(n + 1)]
#
#dp[1][1][0] = 0
#dp[1][0][1] = 0
#
#for i in range(2,n + 1):
# for j in range(1,n // 2 + 1):
# dp[i][j][0] = min(dp[i - 1][j - 1][0], dp[i - 1][j - 1][1] + l[i - 1])
# dp[i][j][1] = min(dp[i - 1][j][1], dp[i - 1][j][0] + l[i - 1])
#print(min(dp[n][n//2][0], dp[n][n//2][1]))
#
dp = [[INF] * 2 for i in range(n // 2 + 1)]
dp[1][0] = 0
dp[0][1] = 0
for i in range(2, n + 1):
for j in range(n // 2, -1, -1):
a = min(dp[j - 1][0], dp[j - 1][1] + l[i - 1])
b = min(dp[j][1], dp[j][0] + l[i - 1])
dp[j][0] = a
dp[j][1] = b
print(max(dp[n//2][0], dp[n//2][1]))
``` | instruction | 0 | 6,525 | 9 | 13,050 |
No | output | 1 | 6,525 | 9 | 13,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7
Submitted Solution:
```
import sys
dp=[0]+[1<<20]*10000
n=int(input())
a=list(map(int,sys.stdin.readlines()))
for i in range(1,n):
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a[i-1]),(dp[i-j],dp[j]+a[i-1])])
print(dp[n//2])
``` | instruction | 0 | 6,526 | 9 | 13,052 |
No | output | 1 | 6,526 | 9 | 13,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7
Submitted Solution:
```
INF = 100000000
n = int(input())
l = [0 if i == 0 else int(input()) for i in range(n)]
dp = [[[INF] * 2 for i in range(n // 2 + 1)] for j in range(n + 1)]
dp[1][1][0] = 0
dp[1][0][1] = 0
for i in range(2,n + 1):
for j in range(1,n // 2 + 1):
dp[i][j][0] = min(dp[i - 1][j - 1][0], dp[i - 1][j - 1][1] + l[i - 1])
dp[i][j][1] = min(dp[i - 1][j][1], dp[i - 1][j][0] + l[i - 1])
print(min(dp[n][n//2][0], dp[n][n//2][1]))
``` | instruction | 0 | 6,527 | 9 | 13,054 |
No | output | 1 | 6,527 | 9 | 13,055 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.