message stringlengths 2 30.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 237 109k | cluster float64 10 10 | __index_level_0__ int64 474 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are visiting a large electronics store to buy a refrigerator and a microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.
You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
Constraints
* All values in input are integers.
* 1 \le A \le 10^5
* 1 \le B \le 10^5
* 1 \le M \le 10^5
* 1 \le a_i , b_i , c_i \le 10^5
* 1 \le x_i \le A
* 1 \le y_i \le B
* c_i \le a_{x_i} + b_{y_i}
Input
Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M
Output
Print the answer.
Examples
Input
2 3 1
3 3
3 3 3
1 2 1
Output
5
Input
1 1 2
10
10
1 1 5
1 1 10
Output
10
Input
2 2 1
3 5
3 5
2 2 2
Output
6
Submitted Solution:
```
A, B, M = map(int, input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
value = min(a) + min(b)
for i in range(M):
x,y,c = list(map(int, input().split()))
if A[x-1] + B[y-1] - c < value:
value = A[x-1] + B[y-1] - c
print(value)
``` | instruction | 0 | 20,958 | 10 | 41,916 |
No | output | 1 | 20,958 | 10 | 41,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are visiting a large electronics store to buy a refrigerator and a microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.
You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
Constraints
* All values in input are integers.
* 1 \le A \le 10^5
* 1 \le B \le 10^5
* 1 \le M \le 10^5
* 1 \le a_i , b_i , c_i \le 10^5
* 1 \le x_i \le A
* 1 \le y_i \le B
* c_i \le a_{x_i} + b_{y_i}
Input
Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M
Output
Print the answer.
Examples
Input
2 3 1
3 3
3 3 3
1 2 1
Output
5
Input
1 1 2
10
10
1 1 5
1 1 10
Output
10
Input
2 2 1
3 5
3 5
2 2 2
Output
6
Submitted Solution:
```
S = [int(e) for e in input().split()]
# S = list(map(int, input().replace(' ', '')))
list_a = [int(e) for e in input().split()]
# list_a = list(map(int, input().replace(' ', '')))
list_b = [int(e) for e in input().split()]
# list_b = list(map(int, input().replace(' ', '')))
dis_list = []
for i in range(S[2]):
dis_list.append([int(e) for e in input().split()])
cost_list = []
for i in list_a:
for j in list_b:
cost_list.append(i+j)
for l in dis_list:
cost_list.append(cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2])
print(min(cost_list))
# print('cost_list:',cost_list)
# print('list_a:',list_a)
# print('list_b:',list_b)
``` | instruction | 0 | 20,959 | 10 | 41,918 |
No | output | 1 | 20,959 | 10 | 41,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are visiting a large electronics store to buy a refrigerator and a microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.
You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
Constraints
* All values in input are integers.
* 1 \le A \le 10^5
* 1 \le B \le 10^5
* 1 \le M \le 10^5
* 1 \le a_i , b_i , c_i \le 10^5
* 1 \le x_i \le A
* 1 \le y_i \le B
* c_i \le a_{x_i} + b_{y_i}
Input
Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M
Output
Print the answer.
Examples
Input
2 3 1
3 3
3 3 3
1 2 1
Output
5
Input
1 1 2
10
10
1 1 5
1 1 10
Output
10
Input
2 2 1
3 5
3 5
2 2 2
Output
6
Submitted Solution:
```
import numpy as np
A,B,M = list(map(int,input().split()))
valueA = list(map(int, input().split()))
#print(valueA)
valueB = list(map(int, input().split()))
#print(valueB)
tickets = np.zeros((M ,3))
for i in range(M):
tickets[i,:] = list(map(int, input().split()))
x1 = int(tickets[0,0])
y1 = int(tickets[0,1])
c1 = int(tickets[0,2])
min_ticket = valueA[x1-1] + valueB[y1-1] - c1
if M != 1:
for i in range(2,M):
xi = int(tickets[i,0])
yi = int(tickets[i,1])
ci = int(tickets[i,2])
value = valueA[xi-1] + valueB[yi-1] - ci
if value < min_ticket:
min_ticket = value
"""
min_itself = valueA[0] + valueB[0]
# ε
¨ι¨γγ£γ¦γγγζιγγγ
for i in range(A):
for j in range(B):
value = valueA[i] + valueB[j]
if value < min_itself:
min_itself = value
min_all = min(min_itself, min_ticket)
"""
minA = min(valueA)
minB = min(valueB)
min_itself = minA + minB
min_all = min(min_itself, min_ticket)
print(min_all)
``` | instruction | 0 | 20,960 | 10 | 41,920 |
No | output | 1 | 20,960 | 10 | 41,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are visiting a large electronics store to buy a refrigerator and a microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.
You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
Constraints
* All values in input are integers.
* 1 \le A \le 10^5
* 1 \le B \le 10^5
* 1 \le M \le 10^5
* 1 \le a_i , b_i , c_i \le 10^5
* 1 \le x_i \le A
* 1 \le y_i \le B
* c_i \le a_{x_i} + b_{y_i}
Input
Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M
Output
Print the answer.
Examples
Input
2 3 1
3 3
3 3 3
1 2 1
Output
5
Input
1 1 2
10
10
1 1 5
1 1 10
Output
10
Input
2 2 1
3 5
3 5
2 2 2
Output
6
Submitted Solution:
```
aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
x1, y1, c1 = list(map(int,input().split()))
x.append(x1)
y.append(y1)
c.append(c1)
price = []
for i in range(aa):
price1 = a[i] + min(b)
price.append(price1)
if i <= m-1:
price.append(a[x[i] - 1] + b[y[i] - 1] - c[i])
print(min(price))
``` | instruction | 0 | 20,961 | 10 | 41,922 |
No | output | 1 | 20,961 | 10 | 41,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,197 | 10 | 44,394 |
Tags: greedy, implementation, math
Correct Solution:
```
import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
a, b, c = map(int, input().split())
ans1 = 0
ans2 = 0
if a < c:
ans1 = 1
if a*b <= c:
ans2 = -1
else:
ans2 = b
else:
ans1 = -1
if b == 1:
ans2 = -1
else:
ans2 = b
print(ans1, ans2)
``` | output | 1 | 22,197 | 10 | 44,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,198 | 10 | 44,396 |
Tags: greedy, implementation, math
Correct Solution:
```
test_case = int(input())
for _ in range(test_case):
a, b, c = map(int, input().split())
if a < c:
print(1, end = ' ')
else:
print(-1, end = ' ')
if a*b > c:
print(b)
else:
print(-1)
``` | output | 1 | 22,198 | 10 | 44,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,199 | 10 | 44,398 |
Tags: greedy, implementation, math
Correct Solution:
```
t = int(input())
for i in range(0, t):
entry = input().split(" ")
a = int(entry[0])
b = int(entry[1])
c = int(entry[2])
# 1 box = b donuts = c dollars
shop1 = -1
shop2 = -1
if a < c:
shop1 = 1
if a * b > c:
shop2 = b
print(shop1, shop2)
``` | output | 1 | 22,199 | 10 | 44,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,200 | 10 | 44,400 |
Tags: greedy, implementation, math
Correct Solution:
```
# key missing ""
t = int(input())
for _ in range(t):
a, b, c = [int(i) for i in input().split()]
if a < c:
x = 1
temp = b * a
if temp <= c:
y = -1
else:
y = b
else:
x = -1
y = b
print(x, y)
``` | output | 1 | 22,200 | 10 | 44,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,201 | 10 | 44,402 |
Tags: greedy, implementation, math
Correct Solution:
```
test =int(input())
for t in range(test):
a,b,c = map(int, input().split())
if a<c:
print(1, end=" ")
else:
print(-1, end=" ")
if a*b>c:
print(b, end=" ")
else:
print(-1, end=" ")
print()
``` | output | 1 | 22,201 | 10 | 44,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,202 | 10 | 44,404 |
Tags: greedy, implementation, math
Correct Solution:
```
for s in[*open(0)][1:]:a1,b1,c1=map(int,s.split());print((-1,1)[a1<c1],2*(a1>=c1)or(-1,b1)[a1*b1>c1])
``` | output | 1 | 22,202 | 10 | 44,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,203 | 10 | 44,406 |
Tags: greedy, implementation, math
Correct Solution:
```
#!/usr/local/bin/python3
'''
Author: andyli
Time: 2020-06-25 22:36:38
'''
def main():
for _ in range(int(input())):
a, b, c = map(int, input().split())
ans1, ans2 = -1, -1
if a < c:
ans1 = 1
if a*b > c:
ans2 = b
print(ans1, ans2)
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 1048576
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# endregion
if __name__ == '__main__':
main()
``` | output | 1 | 22,203 | 10 | 44,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. | instruction | 0 | 22,204 | 10 | 44,408 |
Tags: greedy, implementation, math
Correct Solution:
```
t=int(input())
for i in range(t):
li=[int(i) for i in input().split()]
a=li[0]
b=li[1]
c=li[2]
if a<(c/b):
ans1=1;
ans2=-1
print(ans1,ans2)
continue
if a>c/b:
ans2=b
if a<c and b!=1:
ans1=1;
else:
ans1=-1;
print(ans1,ans2)
continue
if a==c/b:
ans2=-1
if a<c and b!=1:
ans1=1;
else:
ans1=-1;
print(ans1,ans2)
continue
``` | output | 1 | 22,204 | 10 | 44,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
from sys import stdin, stdout
import sys
INF=1e11
import math
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split())
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
from collections import defaultdict
for _ in range(int(stdin.readline())):
a,b,c=get_ints()
x=math.floor(c/a)
if a>=c:
print(-1,end=" ")
else:
print(1,end=" ")
if a*b<=c:
print(-1)
else:
print(b)
``` | instruction | 0 | 22,205 | 10 | 44,410 |
Yes | output | 1 | 22,205 | 10 | 44,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
#!/usr/bin/python
t = int(input())
while t > 0:
t -= 1
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
if a >= c :
print("-1 " + str(b))
continue
if a * b <= c:
print("1 -1")
continue
print("1 " + str(b))
``` | instruction | 0 | 22,206 | 10 | 44,412 |
Yes | output | 1 | 22,206 | 10 | 44,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
def process(a, b, c):
fir = 0
sec = 0
if a == c / b:
return [1, -1]
if a > c / b:
if a >= c:
return [-1, b]
else:
return [1, b]
else:
return [1, -1]
if __name__ == "__main__":
num = int(input(""))
for i in range(num):
a, b, c = input("").split(" ")
fir, sec = process(int(a), int(b), int(c))
print("{} {}".format(fir, sec))
``` | instruction | 0 | 22,207 | 10 | 44,414 |
Yes | output | 1 | 22,207 | 10 | 44,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
for _ in range(int(input())):
a, b, c = [int(__) for __ in input().split()]
ans1 = 0
ans2 = 0
if a > c:
ans1 = -1
ans2 = 1
if c == a:
ans1 = -1
ans2 = 2
if a < c:
ans1 = 1
if b * a > c:
ans2 = b
else:
ans2 = -1
print(ans1, ans2)
``` | instruction | 0 | 22,208 | 10 | 44,416 |
Yes | output | 1 | 22,208 | 10 | 44,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
for _ in range(int(input())):
a,b,c = map(int,input().split())
if a>=c:
print('-1',b)
elif a==c//b:
print(1,'-1')
else:
print('1',b)
``` | instruction | 0 | 22,209 | 10 | 44,418 |
No | output | 1 | 22,209 | 10 | 44,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
i = int(input())
for o in range(i):
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
if a > c or a == c:
print("-1 1")
elif (a*2) > c:
print("1 2")
else:
print("1 -1")
``` | instruction | 0 | 22,210 | 10 | 44,420 |
No | output | 1 | 22,210 | 10 | 44,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
t=int(input())
for _ in range(t):
a,b,c=map(int,input().split())
if(a<c):
print("1",end=" ")
else:
print("-1",end=" ")
if(a*b>c):
print(b)
else:
print("1")
``` | instruction | 0 | 22,211 | 10 | 44,422 |
No | output | 1 | 22,211 | 10 | 44,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of testcases.
Each of the next t lines contains three integers a, b and c (1 β€ a β€ 10^9, 2 β€ b β€ 10^9, 1 β€ c β€ 10^9).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9.
If there is no such x, then print -1. If there are multiple answers, then print any of them.
Example
Input
4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000
Output
-1 20
8 -1
1 2
-1 1000000000
Note
In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.
In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.
In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.
In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop.
Submitted Solution:
```
def solution(a,b,c):
ans = [0,0]
if c <= a :
ans[0] = -1
ans[1] = b
elif b * a == c :
if b == 1 :
ans[0] = -1
else:
ans[0] = b + 1
ans[1] = - 1
else:
ans[0] = 1
cond = True
val = 1
if a > c/b :
while cond :
cost1 = a * b * val
cost2 = c * val
if cost2 < cost1 :
ans[1] = b*val
cond =False
val = val + 1
else:
ans[1] = -1
return ans
for _ in range(int(input())):
a,b,c = map(int,input().split())
ans = solution(a,b,c)
print(*ans )
``` | instruction | 0 | 22,212 | 10 | 44,424 |
No | output | 1 | 22,212 | 10 | 44,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,543 | 10 | 45,086 |
Tags: binary search, data structures, implementation
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
# sys.setrecursionlimit(300000)
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
# sys.setrecursionlimit(300000)
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")
# -------------------game starts now----------------------------------------------------import math
# -----------------------------------------------binary seacrh tree---------------------------------------
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
"""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):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <=key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
n,c,dw=map(int,input().split())
d=[]
d1=[]
for i in range(n):
a,b,c1=map(str,input().split())
if c1=="C":
d.append((int(b),int(a)))
else:
d1.append((int(b), int(a)))
d.sort()
d1.sort()
ans=0
l=[]
l1=[]
val=[]
val1=[]
beau=[]
beau1=[]
m=0
m1=0
for i in range(len(d)):
if d[i][0]<=c:
l.append(d[i])
val.append(d[i][0])
beau.append(d[i][1])
m=max(d[i][1],m)
else:
break
for i in range(len(d1)):
if d1[i][0]<=dw:
l1.append(d1[i])
val1.append(d1[i][0])
beau1.append(d1[i][1])
m1=max(m1,d1[i][1])
else:
break
if m!=0 and m1!=0:
ans=m+m1
s=SegmentTree(beau)
s1=SegmentTree(beau1)
for i in range(len(l)):
rem=c-l[i][0]
m=binarySearchCount(val,len(val),rem)
if m==0 or i==0:
continue
ans=max(ans,l[i][1]+s.query(0,min(i-1,m-1)))
for i in range(len(l1)):
rem=dw-l1[i][0]
m=binarySearchCount(val1,len(val1),rem)
if m==0 or i==0:
continue
ans=max(ans,l1[i][1]+s1.query(0,min(i-1,m-1)))
print(ans)
``` | output | 1 | 22,543 | 10 | 45,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,544 | 10 | 45,088 |
Tags: binary search, data structures, implementation
Correct Solution:
```
import operator
import itertools
import bisect
def maxl(l, m, mx):
l.sort(key=operator.itemgetter(1))
lp = [p for(b, p) in l]
lb = list(itertools.accumulate((b for (b, p) in l), max))
for i, ((b, p), mb) in enumerate(zip(l, lb)):
k = bisect.bisect_right(lp, m - p, 0, i)
if k:
x = b + lb[k - 1]
if x > mx:
mx = x
return mx
fc = []
fd = []
n, c, d = map(int, input().split())
for _ in range(n):
b, p, m = input().split()
b, p = int(b), int(p)
f, cd = (fc, c) if m == 'C' else (fd, d)
if p <= cd:
f.append((b, p))
mx = 0
if fc and fd:
bc, pc = max(fc, key=operator.itemgetter(0))
bd, pd = max(fd, key=operator.itemgetter(0))
mx = bc + bd
mx = maxl(fc, c, mx)
mx = maxl(fd, d, mx)
print(mx)
``` | output | 1 | 22,544 | 10 | 45,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,545 | 10 | 45,090 |
Tags: binary search, data structures, implementation
Correct Solution:
```
n, t, d = map(int, input().split())
coin = [[(0, 0), (0, 0)] for i in range(100001)]
diam = [[(0, 0), (0, 0)] for i in range(100001)]
f = []
for i in range(n):
b, c, q = input().split()
b = int(b)
c = int(c)
if q == 'C':
f.append((b, c, 1))
if coin[c][0][0] < b:
coin[c][1] = coin[c][0]
coin[c][0] = (b, i)
elif coin[c][1][0] < b:
coin[c][1] = (b, i)
else:
f.append((b, c, 2))
if diam[c][0][0] < b:
diam[c][1] = diam[c][0]
diam[c][0] = (b, i)
elif diam[c][1][0] < b:
diam[c][1] = (b, i)
for i in range(2, 100001):
if coin[i][0][0] < coin[i - 1][0][0]:
coin[i][1] = max(coin[i][0], coin[i - 1][1])
coin[i][0] = coin[i - 1][0]
else:
coin[i][1] = max(coin[i - 1][1], coin[i][1])
if diam[i][0][0] < diam[i - 1][0][0]:
diam[i][1] = max(diam[i][0], diam[i - 1][1])
diam[i][0] = diam[i - 1][0]
else:
diam[i][1] = max(diam[i - 1][1], diam[i][1])
p = False
ans = 0
for i in range(n):
fnt = f[i]
#print(fnt)
if fnt[2] == 1:
if t >= fnt[1]:
s = t - fnt[1]
if coin[s][0][0] > 0 and coin[s][0][1] != i:
ans = max(fnt[0] + coin[s][0][0], ans)
p = True
elif coin[s][1][0] > 0:
ans = max(fnt[0] + coin[s][1][0], ans)
p = True
if diam[d][0][0] > 0:
ans = max(fnt[0] + diam[d][0][0], ans)
p = True
else:
if d >= fnt[1]:
s = d - fnt[1]
if diam[s][0][0] > 0 and diam[s][0][1] != i:
ans = max(fnt[0] + diam[s][0][0], ans)
p = True
elif diam[s][1][0] > 0:
ans = max(fnt[0] + diam[s][1][0], ans)
p = True
if coin[t][0][0] > 0:
ans = max(fnt[0] + coin[t][0][0], ans)
p = True
if p:
print(ans)
else:
print(0)
``` | output | 1 | 22,545 | 10 | 45,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,546 | 10 | 45,092 |
Tags: binary search, data structures, implementation
Correct Solution:
```
import operator
import itertools
import bisect
def maxl(l, m, mx):
l.sort(key=operator.itemgetter(1))
lp = [p for(b, p) in l]
lb = list(itertools.accumulate((b for (b, p) in l), max))
for i, (b, p) in enumerate(l):
k = bisect.bisect_right(lp, m - p, 0, i)
if k:
x = b + lb[k - 1]
if x > mx:
mx = x
return mx
fc = []
fd = []
n, c, d = map(int, input().split())
for _ in range(n):
b, p, m = input().split()
b, p = int(b), int(p)
f, cd = (fc, c) if m == 'C' else (fd, d)
if p <= cd:
f.append((b, p))
mx = 0
if fc and fd:
bc = max(b for (b, p) in fc)
bd = max(b for (b, p) in fd)
mx = bc + bd
mx = maxl(fc, c, mx)
mx = maxl(fd, d, mx)
print(mx)
``` | output | 1 | 22,546 | 10 | 45,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,547 | 10 | 45,094 |
Tags: binary search, data structures, implementation
Correct Solution:
```
import operator
import itertools
import bisect
def maxl(l, m, mx):
l.sort(key=operator.itemgetter(1))
m1, m2 = 0, 0
pp = None
for b, p in l:
if p != pp:
if 2 * p > m:
break
if m1 and m2 and m1 + m2 > mx:
mx = m1 + m2
m1, m2 = b, 0
pp = p
else:
if b > m1:
m1, m2 = b, m1
elif b > m2:
m2 = b
if m1 and m2 and m1 + m2 > mx:
mx = m1 + m2
lp = [p for(b, p) in l]
lb = list(itertools.accumulate((b for (b, p) in l), max))
for i, ((b, p), mb) in enumerate(zip(l, lb)):
p1 = min(m - p, p - 1)
k = bisect.bisect_right(lp, p1, 0, i)
if k:
x = b + lb[k - 1]
if x > mx:
mx = x
return mx
fc = []
fd = []
n, c, d = map(int, input().split())
for _ in range(n):
b, p, m = input().split()
b, p = int(b), int(p)
f, cd = (fc, c) if m == 'C' else (fd, d)
if p <= cd:
f.append((b, p))
mx = 0
if fc and fd:
bc, pc = max(fc, key=operator.itemgetter(0))
bd, pd = max(fd, key=operator.itemgetter(0))
mx = bc + bd
mx = maxl(fc, c, mx)
mx = maxl(fd, d, mx)
print(mx)
``` | output | 1 | 22,547 | 10 | 45,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,548 | 10 | 45,096 |
Tags: binary search, data structures, implementation
Correct Solution:
```
n,c,d=list(map(int,input().strip().split(' ')))
import bisect
FC=[]
FD=[]
for _ in range(n):
A,B,C=list(input().strip().split(' '))
A=int(A)
B=int(B)
if C=='C':
if B<=c:
FC+=[[int(A),int(B)]]
else:
if B<=d:
FD+=[[int(A),int(B)]]
MAXcd=0
if len(FC)>=1 and len(FD)>=1:
MAXc=0
for i in range(len(FC)):
if FC[i][0]>MAXc:
MAXc=FC[i][0]
MAXd=0
for i in range(len(FD)):
if FD[i][0]>MAXd:
MAXd=FD[i][0]
MAXcd=MAXc+MAXd
def find(FC,c):
if len(FC)<=1:
return 0
rFC=[[FC[i][1],FC[i][0],i] for i in range(len(FC))]
rFC=sorted(rFC)
#print(rFC,c)
cost=[rFC[i][0] for i in range(len(rFC))]
if rFC[0][0]+rFC[1][0]>c:
return 0
MAXc=rFC[0][1]+rFC[1][1]
#print(MAXc,'init')
counting=[]
MAX=rFC[0][1]
counting+=[MAX]
for i in range(1,len(rFC)):
if rFC[i][1]>MAX:
MAX=rFC[i][1]
counting+=[MAX]
#print(counting)
#print(cost)
for i in range(1,len(rFC)):
ans=rFC[i][1]
temp=rFC[i][0]
position=bisect.bisect_right(cost,min(temp-1,c-temp))-1
#print(position,i,'position ,i ')
if position!=-1:
ans+=counting[position]
#print(ans,i,'ans,i')
if ans>MAXc and position!=-1:
MAXc=ans
COUNT=[[] for i in range(100001)]
for i in range(len(rFC)):
COUNT[rFC[i][0]]+=[rFC[i][1]]
for i in range(0,len(COUNT)):
if 2*i<=c:
if len(COUNT[i])>=2:
COUNT[i]=sorted(COUNT[i])
ans=COUNT[i][-1]+COUNT[i][-2]
if ans>MAXc:
MAXc=ans
return MAXc
MAXc=find(FC,c)
MAXd=find(FD,d)
print(max(MAXcd,MAXc,MAXd))
``` | output | 1 | 22,548 | 10 | 45,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,549 | 10 | 45,098 |
Tags: binary search, data structures, implementation
Correct Solution:
```
import operator
def maxl(l, m, mx):
for i in range(len(l) - 1):
b1, p1 = l[i]
for j in range(i + 1, len(l)):
b2, p2 = l[j]
if b1 + b2 <= mx:
break
if p1 + p2 <= m:
mx = b1 + b2
break
return mx
fc = []
fd = []
n, c, d = map(int, input().split())
for _ in range(n):
b, p, m = input().split()
b, p = int(b), int(p)
if m == 'C':
if p <= c:
fc.append((b, p))
else:
if p <= d:
fd.append((b, p))
fc.sort(key=operator.itemgetter(0), reverse=True)
fd.sort(key=operator.itemgetter(0), reverse=True)
mx = fc[0][0] + fd[0][0] if fc and fd else 0
mx = maxl(fc, c, mx)
mx = maxl(fd, d, mx)
print(mx)
``` | output | 1 | 22,549 | 10 | 45,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins. | instruction | 0 | 22,550 | 10 | 45,100 |
Tags: binary search, data structures, implementation
Correct Solution:
```
#!/usr/bin/env python3
from sys import stdin,stdout
def rint():
return map(int, stdin.readline().split())
#lines = stdin.readlines()
n, c, d = rint()
def mt(T, index, a):
maxb0 = 0
maxb1 = 0
for i, j in enumerate(a):
p, b = j
if maxb0 < b:
maxb1 = maxb0
maxb0 = b
index[i] = i
elif maxb1 < b:
maxb1 = b
index[i] = index[i-1]
else:
index[i] = index[i-1]
T[i][0] = maxb0
T[i][1] = maxb1
def findmax(T, a, c, index):
maxb = 0
if len(a) == 0:
return 0
for i, j in enumerate(a):
p, b = j
#print(i, p, b, c)
if c - p <= 0:
break
i2 = findai(a, c-p)
if i2 == -1:
continue
#print("i2 is", i2)
if i == index[i2]:
bb = T[i2][1]
else:
bb = T[i2][0]
if bb == 0:
b = 0
maxb = max(maxb, bb+b)
#print("maxb is", maxb, i)
#print("maxb is", maxb)
return maxb
# find T index in which price is less or equal than p
def findai(a, p):
#print(a)
#print(p)
s = 0
e = len(a)
if a[0][0] > p:
return -1
while e-s > 1:
i = (s+e)//2
#print(s, i, e)
if a[i][0] <= p:
s = i
else:
e = i
#print("index is", s)
return s
a = []
b = []
for i in range(n):
bb, pp, tt = input().split()
bb = int(bb)
pp = int(pp)
if tt == "C":
a.append([pp, bb])
else:
b.append([pp, bb])
la = len(a)
lb = len(b)
a.sort()
b.sort()
TA = [[0,0] for i in range(la)]
TB = [[0,0] for i in range(lb)]
TAi = [-1 for i in range(la)]
TBi = [-1 for i in range(lb)]
mt(TA, TAi, a)
mt(TB, TBi, b)
ci = -1
di = -1
if len(a):
ci = findai(a, c)
if len(b):
di = findai(b, d)
if ci == -1 or di == -1:
cd = 0
else:
cd = TA[ci][0] + TB[di][0]
#print("cd is", cd)
ans = max(findmax(TA, a, c, TAi), findmax(TB, b, d, TBi), cd)
print(ans)
``` | output | 1 | 22,550 | 10 | 45,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
# -*- coding: utf-8 -*-
def main():
# n = 6
#coins = 68
# diamonds = 40
# fountains = [(1,18,"D"), (6,16,"D"), (11,16,"D"), (7,23,"D"), (16,30,"D"),
# (2,20,"D")]
fountains_c = []
fountains_d = []
n, coins, diamonds = [int(x) for x in input().split()]
for _ in range(n):
beauty, cost, type = input().split()
#beauty, cost, type = fountains[_]
beauty = int(beauty)
cost = int(cost)
if type == "C":
if cost > coins:
continue
fountains_c.append((beauty, cost))
elif type == "D":
if cost > diamonds:
continue
fountains_d.append((beauty, cost))
else:
raise Exception("Invalid type")
fountains_c = sorted(fountains_c, key = lambda tup: tup[0], reverse = True)
fountains_d = sorted(fountains_d, key = lambda tup: tup[0], reverse = True)
n_c = len(fountains_c)
n_d = len(fountains_d)
max_beauty = 0
if n_c == 0 and n_d == 0:
return 0
if n_c > 0 and n_d > 0:
max_beauty = fountains_c[0][0] + fountains_d[0][0]
for i in range(n_c-1):
for j in range(i+1,n_c):
if fountains_c[i][0] + fountains_c[j][0] <= max_beauty:
break
if (fountains_c[i][1] + fountains_c[j][1]) <= coins:
assert fountains_c[i][0] + fountains_c[j][0] > max_beauty
max_beauty = fountains_c[i][0] + fountains_c[j][0]
break
for i in range(n_d-1):
for j in range(i+1,n_d):
if fountains_d[i][0] + fountains_d[j][0] <= max_beauty:
break
if (fountains_d[i][1] + fountains_d[j][1]) <= diamonds:
assert fountains_d[i][0] + fountains_d[j][0] > max_beauty
max_beauty = fountains_d[i][0] + fountains_d[j][0]
break
return max_beauty
print(main())
``` | instruction | 0 | 22,551 | 10 | 45,102 |
Yes | output | 1 | 22,551 | 10 | 45,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
import sys
from operator import itemgetter
from bisect import bisect
inf = 1<<30
def solve():
n, c, d = map(int, input().split())
cs = []
ds = []
b = [0] * n
p = [0] * n
for i in range(n):
bi, pi, ti = sys.stdin.readline().split()
bi = int(bi)
pi = int(pi)
b[i] = bi
p[i] = pi
if ti == 'C':
cs.append((pi, bi, i))
else:
ds.append((pi, bi, i))
cs.sort()
ds.sort()
# print('cs:', cs, file=sys.stderr)
# print('ds:', ds, file=sys.stderr)
fc = [[-1]*2 for i in range(c + 1)]
fd = [[-1]*2 for i in range(d + 1)]
lc = 0
for w in range(1, c + 1):
fc[w] = fc[w - 1][:]
if lc < len(cs) and w == cs[lc][0]:
for j in range(lc, len(cs)):
if cs[j][0] > w:
lc = j
break
if fc[w][0] == -1 or cs[j][1] > b[fc[w][0]]:
fc[w][0], fc[w][1] = cs[j][2], fc[w][0]
elif fc[w][1] == -1 or cs[j][1] > b[fc[w][1]]:
fc[w][1] = cs[j][2]
else:
lc = len(cs)
ld = 0
for w in range(1, d + 1):
fd[w] = fd[w - 1][:]
if ld < len(ds) and w == ds[ld][0]:
for j in range(ld, len(ds)):
if ds[j][0] > w:
ld = j
break
if fd[w][0] == -1 or ds[j][1] > b[fd[w][0]]:
fd[w][0], fd[w][1] = ds[j][2], fd[w][0]
elif fd[w][1] == -1 or ds[j][1] > b[fd[w][1]]:
fd[w][1] = ds[j][2]
else:
ld = len(ds)
'''
for i in range(1, d + 1):
print('{}:{}'.format(i, fd[i]))
'''
ans = 0
if fc[c][0] != -1 and fd[d][0] != -1: # (C, D)
ans = max(ans, b[fc[c][0]] + b[fd[d][0]])
for cpi, cbi, i in cs: # (C, C)
if c - cpi <= 0:
break
if fc[c - cpi][0] != -1:
if fc[c - cpi][0] != i:
ans = max(ans, b[i] + b[fc[c - cpi][0]])
elif fc[c - cpi][1] != -1:
ans = max(ans, b[i] + b[fc[c - cpi][1]])
else:
break
for dpi, dbi, i in ds: # (D, D)
if d - dpi <= 0:
break
if fd[d - dpi][0] != -1:
if fd[d - dpi][0] != i:
ans = max(ans, b[i] + b[fd[d - dpi][0]])
elif fd[d - dpi][1] != -1:
ans = max(ans, b[i] + b[fd[d - dpi][1]])
else:
break
print(ans)
if __name__ == '__main__':
solve()
``` | instruction | 0 | 22,552 | 10 | 45,104 |
Yes | output | 1 | 22,552 | 10 | 45,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
def get_max(arr, m, curr_max):
for i in range(len(arr) - 1):
b1, p1 = arr[i]
if 2 * b1 <= curr_max:
break
for j in range(i+1, len(arr)):
b2, p2 = arr[j]
if b1 + b2 <= curr_max:
break
if p1 + p2 <= m:
curr_max = b1 + b2
break
return curr_max
fd, fc = [], []
n, c, d = map(int, input().split())
for _ in range(n):
b, p, m = input().split()
b, p = int(b), int(p)
if m == 'C':
if p <= c:
fc.append((b, p))
else:
if p <= d:
fd.append((b, p))
fc = sorted(fc, reverse=True)
fd = sorted(fd, reverse=True)
res = fc[0][0] + fd[0][0] if fc and fd else 0
res = get_max(fc, c, res)
res = get_max(fd, d, res)
print(res)
``` | instruction | 0 | 22,553 | 10 | 45,106 |
Yes | output | 1 | 22,553 | 10 | 45,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
import operator
import itertools
import bisect
def maxl(l, m, mx):
l.sort(key=operator.itemgetter(1))
lp = [p for(b, p) in l]
lb = list(itertools.accumulate((b for (b, p) in l), max))
for i, (b, p) in enumerate(l):
k = bisect.bisect_right(lp, m - p, 0, i)
if k:
x = b + lb[k - 1]
if x > mx:
mx = x
return mx
fc = []
fd = []
n, c, d = map(int, input().split())
for _ in range(n):
b, p, m = input().split()
b, p = int(b), int(p)
f, cd = (fc, c) if m == 'C' else (fd, d)
if p <= cd:
f.append((b, p))
mx = 0
if fc and fd:
bc = max(b for (b, p) in fc)
bd = max(b for (b, p) in fd)
mx = bc + bd
mx = maxl(fc, c, mx)
mx = maxl(fd, d, mx)
print(mx)
# Made By Mostafa_Khaled
``` | instruction | 0 | 22,554 | 10 | 45,108 |
Yes | output | 1 | 22,554 | 10 | 45,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
class F:
def __init__(self,b,p):
self.b = b
self.p = p
def __lt__(self,other):
if self.p == other.p:
return self.b<other.b
return self.p<other.p
n,c,d = map(int,input().split())
cc = []
dd = []
for i in range(n):
a = input().split()
b = int(a[0])
p = int(a[1])
temp = F(b,p)
if a[2] == 'C':
if p <= c:
cc.append(temp)
else:
if p <= d:
dd.append(temp)
cc.sort()
dd.sort()
ans = 0
if len(cc) != 0:
ans += cc[-1].b
if len(dd) != 0:
ans += dd[-1].b
l = 0
r = len(cc)-1
while l <= r:
if cc[l].p + cc[r].p > c:
r -= 1
elif cc[l].b+cc[r].b > ans:
ans = cc[l].b+cc[r].b
l += 1
else:
l += 1
l = 0
r = len(dd)-1
while l <= r:
if dd[l].p + dd[r].p > c:
r -= 1
elif dd[l].b+dd[r].b > ans:
ans = dd[l].b+dd[r].b
l += 1
else:
l += 1
print(ans)# your code goes here
``` | instruction | 0 | 22,555 | 10 | 45,110 |
No | output | 1 | 22,555 | 10 | 45,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
n,c,d=map(int,input().split())
coin=[]
diamond=[]
for i in range(n):
x,y,z=input().split()
if z =="C":
coin.append([int(i) for i in [x,y]])
else:
diamond.append([int(i) for i in [x,y]])
coin=sorted(coin,key=lambda x:x[0],reverse=True)
diamond=sorted(diamond,key=lambda x:x[0],reverse=True)
s=0
a=0
beauty=0
i=0
while True:
if i>len(coin)-1:
break
s+=coin[i][1]
if s<=c and i<=len(coin):
beauty+=coin[i][0]
i+=1
elif s>c:
s-=coin[i][1]
i+=1
i=0
while True:
if i>len(diamond)-1:
break
a+=diamond[i][1]
if a<=d and i<=len(diamond):
beauty+=diamond[i][0]
i+=1
elif a>d:
a-=diamond[i][1]
i+=1
print(beauty)
``` | instruction | 0 | 22,556 | 10 | 45,112 |
No | output | 1 | 22,556 | 10 | 45,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
n, c, d = map(int, input().split())
coin = [[(0, 0), (0, 0)] for i in range(100001)]
diam = [[(0, 0), (0, 0)] for i in range(100001)]
f = []
for i in range(n):
b, c, q = input().split()
b = int(b)
c = int(c)
if q == 'C':
f.append((b, c, 1))
if coin[c][0][0] < b:
coin[c][1] = coin[c][0]
coin[c][0] = (b, i)
elif coin[c][1][0] < b:
coin[c][1] = (b, i)
else:
f.append((b, c, 2))
if diam[c][0][0] < b:
diam[c][1] = diam[c][0]
diam[c][0] = (b, i)
elif diam[c][1][0] < b:
diam[c][1] = (b, i)
for i in range(2, 100001):
if coin[i][0][0] < coin[i - 1][0][0]:
coin[i][1] = max(coin[i][0], coin[i - 1][1])
coin[i][0] = coin[i - 1][0]
else:
coin[i][1] = max(coin[i - 1][1], coin[i][1])
if diam[i][0][0] < diam[i - 1][0][0]:
diam[i][1] = max(diam[i][0], diam[i - 1][1])
diam[i][0] = diam[i - 1][0]
else:
diam[i][1] = max(diam[i - 1][1], diam[i][1])
p = False
ans = 0
for i in range(n):
fnt = f[i]
#print(fnt)
if fnt[2] == 1:
if c > fnt[1]:
s = c - fnt[1]
if coin[s][0][0] > 0 and coin[s][0][1] != i:
ans = max(fnt[0] + coin[s][0][0], ans)
p = True
elif coin[s][1][0] > 0:
ans = max(fnt[0] + coin[s][1][0], ans)
p = True
if diam[d][0][0] > 0:
ans = max(fnt[0] + diam[d][0][0], ans)
p = True
else:
if d > fnt[1]:
s = d - fnt[1]
if diam[s][0][0] > 0 and diam[s][0][1] != i:
ans = max(fnt[0] + diam[s][0][0], ans)
p = True
elif diam[s][1][0] > 0:
ans = max(fnt[0] + diam[s][1][0], ans)
p = True
if coin[c][0][0] > 0:
ans = max(fnt[0] + coin[c][0][0], ans)
p = True
if p:
print(ans)
else:
print(0)
``` | instruction | 0 | 22,557 | 10 | 45,114 |
No | output | 1 | 22,557 | 10 | 45,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 β€ n β€ 100 000, 0 β€ c, d β€ 100 000) β the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 β€ bi, pi β€ 100 000) β the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
Examples
Input
3 7 6
10 8 C
4 3 C
5 6 D
Output
9
Input
2 4 5
2 5 C
2 1 D
Output
0
Input
3 10 10
5 5 C
5 5 C
10 11 D
Output
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
Submitted Solution:
```
def main():
n,c,d=list(map(int,input().strip().split(' ')))
FF=[]
countc=0
countd=0
#B=[[b_i,c_i]], find max(b_i+b_j:c_i+c_j<=c)
import bisect
def findout(B,c):
CC=[]
cost=[]
for i in range(len(B)):
CC+=[[B[i][1],B[i][0]]]
cost+=[B[i][1]]
CC=sorted(CC)
if CC[0][0]+CC[1][0]>c:
return 0
counting=[]
#MAX=0
MAX=CC[0][1]
counting+=[MAX]
for i in range(1,len(B)):
if CC[i][1]>MAX:
MAX=CC[i][1]
counting+=[MAX]
MAX=0
for i in range(len(B)):
ans=0
ans+=B[i][0]
position=bisect.bisect_right(cost,c-B[i][1])-1
if position<len(B) and position>0:
ans+=counting[position]
if ans>MAX:
MAX=ans
return MAX
for i in range(n):
b,cost,ty=list(input().strip().split(' '))
b=int(b)
cost=int(cost)
if ty=='C':
if c>=cost:
FF+=[[b,cost,ty]]
countc+=1
if ty=='D':
if d>=cost:
FF+=[[b,cost,ty]]
countd+=1
FF=sorted(FF)
FF=FF[::-1]
##three possible CC,CD,DD
#case1 CC:
MAXc=0
MAX=0
if countc>=2:
ans=0
CCC=[]
for i in range(len(FF)):
if FF[i][2]=='C':
CCC+=[[FF[i][0],FF[i][1]]]
MAX=findout(CCC,c)
MAXc=MAX
MAXd=0
MAX=0
if countd>=2:
ans=0
CCC=[]
for i in range(len(FF)):
if FF[i][2]=='D':
CCC+=[[FF[i][0],FF[i][1]]]
MAX=findout(CCC,d)
MAXd=MAX
ans=0
total=0
if countd>=1 and countc>=1:
usedc=0
usedd=0
total=0
for i in range(len(FF)):
if usedc==1 and usedd==1:
break
else:
if FF[i][2]=='C':
if usedc==0:
total+=FF[i][0]
usedc=1
else:
if usedd==0:
total+=FF[i][0]
usedd=1
MAXcd=total
if countc+countd<2:
print(0)
else:
print(max(MAXc,MAXd,MAXcd))
main()
``` | instruction | 0 | 22,558 | 10 | 45,116 |
No | output | 1 | 22,558 | 10 | 45,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
test_cases = int(input())
for test_case in range(1, test_cases + 1):
number_of_pieces, unnecessary_weight = list(map(int, input().split()))
pieces = sorted(list(map(int, input().split())), reverse=True)
if sum(pieces) == unnecessary_weight:
print("NO")
else:
index = 0
result = []
current_sum = 0
whole_sum = sum(pieces)
while index < len(pieces):
if current_sum > unnecessary_weight:
break
if current_sum + pieces[index] == unnecessary_weight:
index += 1
continue
current_sum += pieces[index]
result.append(pieces.pop(index))
if current_sum > unnecessary_weight:
result += pieces
current_sum += sum(pieces)
pieces = []
if pieces:
if current_sum + sum(pieces) == whole_sum and current_sum != unnecessary_weight:
result += pieces
current_sum += sum(pieces)
pieces = []
if current_sum == whole_sum:
print("YES")
print(" ".join(map(str, result)))
else:
print("NO")
``` | instruction | 0 | 23,106 | 10 | 46,212 |
Yes | output | 1 | 23,106 | 10 | 46,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
######################################################################
#Input Method#########################################################
from sys import stdin
class IOI:
def nextInt(self):
return int(stdin.readline().strip())
def Int(self):
return map(int, stdin.readline().strip().split())
def Str(self):
return stdin.readline().strip()
def Array(self):
return list(map(int, stdin.readline().strip().split()))
######################################################################
def calculate(n, x, arr):
totSum = sum(arr)
if totSum == x:
print("NO")
return
print("YES")
curSum = 0
i = 0
while i < n:
if curSum + arr[i] == x:
if i < n-1:
arr[i], arr[i+1] = arr[i+1], arr[i]
else:
arr[i-1], arr[i] = arr[i], arr[i-1]
curSum += arr[i]
i += 1
print(*arr)
input = IOI()
t = input.nextInt()
while t:
n, x = input.Int()
arr = input.Array()
calculate(n, x, arr)
t -= 1
``` | instruction | 0 | 23,107 | 10 | 46,214 |
Yes | output | 1 | 23,107 | 10 | 46,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
count = int(input())
for i in range(count):
num_x = input().split()
x = int(num_x[1])
num = int(num_x[0])
num_list = input().split()
for j in range(num):
num_list[j] = int(num_list[j])
num_list.sort()
sum_num = 0
for q in range(num):
sum_num += num_list[q]
if x == sum_num:
print('NO')
elif x > sum_num:
print('YES')
for q in range(len(num_list)):
print("{}".format(num_list[q]), end=' ')
print('\n')
else:
sum_i = 0
print('YES')
for s in range(len(num_list)):
sum_i += num_list[s]
if sum_i == x:
t = num_list[s]
num_list[s] = num_list[s+1]
num_list[s+1] = t
break
for q in range(len(num_list)):
print("{}".format(num_list[q]), end=' ')
print('\n')
``` | instruction | 0 | 23,108 | 10 | 46,216 |
Yes | output | 1 | 23,108 | 10 | 46,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
for _ in range(int(input())):
n, x = map(int, input().split())
lst = list(map(int,input().split()))
if sum(lst) == x :
print('No')
else:
c = 0
for i in range(n):
c += lst[i]
if(c == x):
lst[i],lst[i + 1]=lst[i + 1],lst[i]
print('YES')
print(' '.join(map(str,lst)))
``` | instruction | 0 | 23,109 | 10 | 46,218 |
Yes | output | 1 | 23,109 | 10 | 46,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
tt = int(input())
while tt > 0:
n, x = map(int,input().split())
l = list(map(int,input().split()))
sl = sorted(l)
rl = sl[::-1]
ans = []
sm = rl[0]
for e in rl:
ans.append(sm)
if sm == x:
break
sm += e
summ = 0
new = []
for e in rl:
summ += e
if summ != x:
new.append(e)
if x in ans:
print('NO')
else:
print('YES')
for e in new:
print(e, end = ' ')
tt -= 1
``` | instruction | 0 | 23,110 | 10 | 46,220 |
No | output | 1 | 23,110 | 10 | 46,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
for t in range(int(input())):
a, x = map(int, input().split())
b = sorted([int(i) for i in input().split()])
b=b[::-1]
pref = b[0]
f = True
if b[0] > x:
print('YES')
print(*b)
continue
if pref == x:
print('NO')
continue
for i in range(1, a):
pref += b[i]
if pref == x:
f = False
break
if not f:
print('NO')
else:
print('YES')
print(*b)
``` | instruction | 0 | 23,111 | 10 | 46,222 |
No | output | 1 | 23,111 | 10 | 46,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
n = int(input())
for i in range(n):
pieces,xplode = map(int,input().split(' '))
l = list(map(int,input().split(' ')))
sum = 0
xp = False
if pieces == 1 and l[0] == xplode:
print('NO')
break
elif pieces == 1 and l[0] != xplode:
print('YES')
break
if l[0] + l[1] == xplode:
temp = l[len(l)-1]
for i in range(len(l)-1,-1,-1):
l[i] = l[i-1]
l[0] = temp
for i in range(len(l)):
sum += l[i]
if sum == xplode:
xp = True
break
if xp:
print('NO')
else:
print('YES')
print(*l)
``` | instruction | 0 | 23,112 | 10 | 46,224 |
No | output | 1 | 23,112 | 10 | 46,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will explode. Can he put all n gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.
Formally, rearrange the array w so that for each i (1 β€ i β€ n), β_{j = 1}^{i}w_j β x.
Input
The input consists of multiple test cases. The first line contains an integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n and x (1 β€ n β€ 100; 1 β€ x β€ 10^4) β the number of gold pieces that Phoenix has and the weight to avoid, respectively.
The second line of each test case contains n space-separated integers (1 β€ w_i β€ 100) β the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.
Output
For each test case, if Phoenix cannot place all n pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array w. If there are multiple solutions, print any.
Example
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
Note
In the first test case, Phoenix puts the gold piece with weight 3 on the scale first, then the piece with weight 2, and finally the piece with weight 1. The total weight on the scale is 3, then 5, then 6. The scale does not explode because the total weight on the scale is never 2.
In the second test case, the total weight on the scale is 8, 9, 11, 14, then 18. It is never 3.
In the third test case, Phoenix must put the gold piece with weight 5 on the scale, and the scale will always explode.
Submitted Solution:
```
for _ in range(int(input())):
n,x = map(int,input().split())
a=list(map(int,input().split()))[:n]
m=max(a)
c=[]
res=[]
if m>x:
print('YES')
print(m,end=' ')
for i in a:
if i!=m:
print(i,end=' ')
print()
elif sum(a)==x:
print('NO')
else:
while True:
if x-m == 0:
c.append(m)
else:
x=x-m
res.append(m)
if x<0:
res=res+c+a
a.remove(m)
if len(a)==0:
break
m=max(a)
if len(res)<n:
print('NO')
else:
print('YES')
print(*res)
``` | instruction | 0 | 23,113 | 10 | 46,226 |
No | output | 1 | 23,113 | 10 | 46,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your search for Heidi is over β you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 β€ i β€ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.
Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.
There is a problem, though. The capacity of the library is k β this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.
You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?
Input
The first line of input will contain two integers n and k (1 β€ n, k β€ 80). The second line will contain n integers a1, a2, ..., an (1 β€ ai β€ n) β the sequence of book requests.
Output
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
Examples
Input
4 80
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Note
In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day. | instruction | 0 | 23,414 | 10 | 46,828 |
Tags: greedy
Correct Solution:
```
n, k = map(int, input().split())
arr = [int(z) for z in input().split()]
books = set()
def latest(n, arr, i, books):
w = {}
for pos in range(i+1, n):
if w.get(arr[pos]):
continue
else:
w[arr[pos]] = pos
for j in books:
if not w.get(j):
w[j] = 10**18
mn = 0
ltr = 0
for j in books:
if w[j] > mn:
mn = w[j]
ltr = j
#print(w)
return ltr
cnt = 0
for i in range(n-1):
if arr[i] not in books:
cnt += 1
if len(books) + 1 > k:
l = latest(n, arr, i, books)
books.remove(l)
books.add(arr[i])
if arr[-1] not in books:
cnt += 1
print(cnt)
``` | output | 1 | 23,414 | 10 | 46,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your search for Heidi is over β you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 β€ i β€ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.
Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.
There is a problem, though. The capacity of the library is k β this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.
You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?
Input
The first line of input will contain two integers n and k (1 β€ n, k β€ 80). The second line will contain n integers a1, a2, ..., an (1 β€ ai β€ n) β the sequence of book requests.
Output
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
Examples
Input
4 80
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Note
In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day. | instruction | 0 | 23,415 | 10 | 46,830 |
Tags: greedy
Correct Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
z=[0]*81
kz,ans=0,0
for i in range(n):
if z[a[i]]: continue
ans+=1
if k>kz:
z[a[i]]=1; kz+=1
else:
h=-1
for j in range(1,n+1):
if z[j]:
m=n+1
for p in range(i,n):
if j==a[p]:
m=p
break
if m>h:
h=m;
t=j
z[t]=0
z[a[i]]=1
print(ans)
# Made By Mostafa_Khaled
``` | output | 1 | 23,415 | 10 | 46,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your search for Heidi is over β you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 β€ i β€ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.
Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.
There is a problem, though. The capacity of the library is k β this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.
You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?
Input
The first line of input will contain two integers n and k (1 β€ n, k β€ 80). The second line will contain n integers a1, a2, ..., an (1 β€ ai β€ n) β the sequence of book requests.
Output
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
Examples
Input
4 80
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Note
In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day. | instruction | 0 | 23,416 | 10 | 46,832 |
Tags: greedy
Correct Solution:
```
R = lambda:map(int, input().split())
stack= []
n, k = R()
l = list(R())
curr,tot = 0,0
for i in range(n):
if l[i] not in stack:
if curr<k:
curr = curr+1
else:
c,z=0,-1
for j in range(k):
if stack[j] not in l[i:]:
z=j
break
else:
c= max(c,i+l[i:].index(stack[j]))
stack.pop(z) if z != -1 else stack.remove(l[c])
stack.insert(0,l[i])
tot+=1
print(tot)
``` | output | 1 | 23,416 | 10 | 46,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your search for Heidi is over β you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 β€ i β€ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.
Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.
There is a problem, though. The capacity of the library is k β this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.
You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?
Input
The first line of input will contain two integers n and k (1 β€ n, k β€ 80). The second line will contain n integers a1, a2, ..., an (1 β€ ai β€ n) β the sequence of book requests.
Output
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
Examples
Input
4 80
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Note
In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day. | instruction | 0 | 23,417 | 10 | 46,834 |
Tags: greedy
Correct Solution:
```
(n,k) = (int(i) for i in input().split())
zapross = [int(i) for i in input().split()]
lave = 0
curh = set()
for i in range(n):
if zapross[i] in curh: continue
if len(curh)!=k:
lave+=1
curh.add(zapross[i])
else:
lpos = -1
cc = -1
for j in curh:
try:
pos = zapross[i+1:].index(j)
except ValueError:
cc = j
break
if pos>lpos:
lpos = pos
cc = j
curh.remove(cc)
curh.add(zapross[i])
lave+=1
print(lave)
``` | output | 1 | 23,417 | 10 | 46,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your search for Heidi is over β you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 β€ i β€ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.
Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.
There is a problem, though. The capacity of the library is k β this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.
You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?
Input
The first line of input will contain two integers n and k (1 β€ n, k β€ 80). The second line will contain n integers a1, a2, ..., an (1 β€ ai β€ n) β the sequence of book requests.
Output
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
Examples
Input
4 80
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Note
In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day. | instruction | 0 | 23,418 | 10 | 46,836 |
Tags: greedy
Correct Solution:
```
from collections import deque
class Treap(): # self.priority_comparator(root.priority, descendant.priority) == True
def __init__(self, key, priority, prrty_cmprtr):
self.key = key
self.priority = priority
self.priority_comparator = prrty_cmprtr
self.left = None
self.right = None
def merge(self, right): # self a.k.a. left <= right ========= tested
if right is None:
return self
if self.priority_comparator(self.priority, right.priority):
root = self
if root.right is not None:
root.right = root.right.merge(right)
else:
root.right = right
else:
root = right
root.left = self.merge(right.left)
return root
def split(self, key): # tested
if self.key <= key:
left = self
if left.right is not None:
left.right, right = left.right.split(key)
else:
left.right, right = None, None
else:
right = self
if right.left is not None:
left, right.left = right.left.split(key)
else:
left, right.left = None, None
return (left, right)
def insert(self, element): # tested
left, right = self.split(element.key)
if left is not None:
t = left.merge(element)
else:
t = element
if right is not None:
return t.merge(right)
return t
def delete(self, key): # UN!tested
left, right = self.split(key)
left, middle = left.split(key - 1)
if left is not None:
return left.merge(right)
return right
def find(self, key):
pos = self
while True:
if key == pos.key:
return True
elif key < pos.key:
if pos.left is None:
return False
pos = pos.left
else:
if pos.right is None:
return False
pos = pos.right
n, k = map(int, input().split())
a = list(map(int, input().split()))
first = [deque() for i in range(n)]
for i in range(n):
first[a[i] - 1].append(i)
first[a[0] - 1].popleft()
if not first[a[0] - 1]:
priority = float('inf')
else:
priority = first[a[0] - 1][0]
treap = Treap(a[0], priority, lambda x, y: x >= y)
l, res = 1, 1
for i in range(1, n):
first[a[i] - 1].popleft()
if not first[a[i] - 1]:
priority = float('inf')
else:
priority = first[a[i] - 1][0]
if not treap.find(a[i]):
if l == k:
treap = treap.delete(treap.key)
l -= 1
if treap is not None:
treap = treap.insert(Treap(a[i], priority, lambda x, y: x >= y))
else:
treap = Treap(a[i], priority, lambda x, y: x >= y)
l += 1
res += 1
else:
treap = treap.delete(a[i])
if treap is not None:
treap = treap.insert(Treap(a[i], priority, lambda x, y: x >= y))
else:
treap = Treap(a[i], priority, lambda x, y: x >= y)
print(res)
``` | output | 1 | 23,418 | 10 | 46,837 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Your search for Heidi is over β you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look at the library's operation during n consecutive days. Heidi knows in advance that on the i-th day (1 β€ i β€ n) precisely one person will come to the library, request to borrow the book ai, read it in a few hours, and return the book later on the same day.
Heidi desperately wants to please all her guests, so she will make sure to always have the book ai available in the library on the i-th day. During the night before the i-th day, she has the option of going to the bookstore (which operates at nights to avoid competition with the library) and buying any book for the price of 1 CHF. Of course, if she already has a book at the library, she does not need to buy it again. Initially, the library contains no books.
There is a problem, though. The capacity of the library is k β this means that at any time, there can be at most k books at the library. If buying a new book would cause Heidi to have more than k books, she must first get rid of some book that she already has, in order to make room for the new book. If she later needs a book that she got rid of, she will need to buy that book again.
You are given k and the sequence of requests for books a1, a2, ..., an. What is the minimum cost (in CHF) of buying new books to satisfy all the requests?
Input
The first line of input will contain two integers n and k (1 β€ n, k β€ 80). The second line will contain n integers a1, a2, ..., an (1 β€ ai β€ n) β the sequence of book requests.
Output
On a single line print the minimum cost of buying books at the store so as to satisfy all requests.
Examples
Input
4 80
1 2 2 1
Output
2
Input
4 1
1 2 2 1
Output
3
Input
4 2
1 2 3 1
Output
3
Note
In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the third test case, before buying book 3 on the third day, she must decide which of the books 1 and 2 she should get rid of. Of course, she should keep the book 1, which will be requested on the fourth day. | instruction | 0 | 23,419 | 10 | 46,838 |
Tags: greedy
Correct Solution:
```
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
library = []
money = 0
for i in range(len(a)):
if a[i] not in library:
money += 1
if len(library) < k:
library.append(a[i])
else:
curmin = n
curindex = 0
found = [n] * len(library)
for j in range(len(a[i+1::])):
if (a[i+j+1] in library) and (found[library.index(a[i+j+1])]==n):
found[library.index(a[i+j+1])] = j
library[found.index(max(found))] = a[i]
print(money)
``` | output | 1 | 23,419 | 10 | 46,839 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.