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 |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,290 | 10 | 190,580 |
Tags: math
Correct Solution:
```
n, m, k, l = [int(i) for i in input().split()]
if k + l> n:
print(-1)
else:
x = (k+l)//m
if (k + l)% m != 0:
x += 1
if m * x >n:
print(-1)
else:
print(x)#different coins m
``` | output | 1 | 95,290 | 10 | 190,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,291 | 10 | 190,582 |
Tags: math
Correct Solution:
```
import math
if __name__ == '__main__':
n,m,k,l = [int (x) for x in input().split()]
if (n- k < l ) :
print(-1)
elif ( m > n) :
print(-1)
elif k+l < m:
print (1)
else :
if (k+l)%m == 0:
print ( (k+l)//m )
elif ((k+l)//m + 1 )*m <= n :
print((k+l)//m + 1)
else:
print(-1)
``` | output | 1 | 95,291 | 10 | 190,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,292 | 10 | 190,584 |
Tags: math
Correct Solution:
```
n,m,k,L = map(int,input().split())
l,r = 0, n//m
while l <= r:
mid = (l+r)//2
if(m*mid - k >= L):
r = mid-1
else:
l = mid+1
l = min(l,n//m)
if(m*l - k >= L):
print(l)
else:
print("-1")
``` | output | 1 | 95,292 | 10 | 190,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,293 | 10 | 190,586 |
Tags: math
Correct Solution:
```
n, m, k, l = list(map(int, input().split()))
if m > n:
print(-1)
exit()
per = n // m
uk1 = 0
if (per * m) >=l+k:
while per - uk1 > 1 :
if ((uk1 + per)//2 * m) < l+k :
uk1 = (uk1 + per)//2
elif ((uk1 + per) // 2 * m) >= l+k:
per = (uk1 + per) // 2
print(per)
else:
print(-1)
``` | output | 1 | 95,293 | 10 | 190,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,294 | 10 | 190,588 |
Tags: math
Correct Solution:
```
def print_return(func):
def wrapper(*args, **kwargs):
retval = func(*args, **kwargs)
print(retval)
return retval
return wrapper
class Solve:
@print_return
# @staticmethod
def solve_a(lines=None):
if lines is None:
n, m, k, l = (int(x) for x in input().split())
else:
n, m, k, l = (int(x) for x in lines[0].split())
x = k + l + m - 1
x //= m
if x * m > n:
return -1
return x
if __name__ == '__main__':
Solve.solve_a()
``` | output | 1 | 95,294 | 10 | 190,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,295 | 10 | 190,590 |
Tags: math
Correct Solution:
```
def Main():
total, friends, collection, limit = map(int, input().split())
mn = (collection + limit + friends - 1) // friends
if(mn * friends <= total):
print(mn)
else :
print('-1')
t = 1
for _ in range(t):
Main()
``` | output | 1 | 95,295 | 10 | 190,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,296 | 10 | 190,592 |
Tags: math
Correct Solution:
```
# -*- coding: utf-8 -*-
import math
def problem(in1):
inputs = list(map(int, in1.split()))
coins = inputs[0]
friends = inputs[1]
ivans_coins = inputs[2]
must_be_new = inputs[3]
gift_coins = ivans_coins + must_be_new
each = gift_coins // friends
if (gift_coins % friends > 0):
each += 1
if (friends * each > coins):
return -1
return each
if __name__ == '__main__':
in1 = input()
result = problem(in1)
print(result)
``` | output | 1 | 95,296 | 10 | 190,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | instruction | 0 | 95,297 | 10 | 190,594 |
Tags: math
Correct Solution:
```
N, M, K, L = map(int, input().split())
ans = (L + K) // M + (0 if (L + K) % M == 0 else 1)
print(ans if M * ans <= N else -1)
``` | output | 1 | 95,297 | 10 | 190,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
n,m,k,l=map(int,input().split())
if m>n:print(-1)
else:
div,mod=(k+l)//m,(k+l)%m
if mod>0:div+=1
if m*div>n:print(-1)
else:print(div)
``` | instruction | 0 | 95,298 | 10 | 190,596 |
Yes | output | 1 | 95,298 | 10 | 190,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
n, m, k, l = list(map(int, input().split()))
target = l + k
perfriend = target // m + (1 if target % m else 0)
if perfriend * m > n or m > n or target > n:
print(-1)
else:
print(perfriend)
``` | instruction | 0 | 95,299 | 10 | 190,598 |
Yes | output | 1 | 95,299 | 10 | 190,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
n,m,k,l=map(int,input().split())
a=(l+k)//m + ((l+k)%m!=0)
if(n>=(l+k)and n>=m and n>=(a*m)):
print((l+k)//m + ((l+k)%m!=0))
else:
print(-1)
``` | instruction | 0 | 95,300 | 10 | 190,600 |
Yes | output | 1 | 95,300 | 10 | 190,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
n, m, k, L = map(int, input().split())
l = 0
r = n // m + 1
while r - l > 1:
med = (r + l) // 2
if med*m - k >= L:
r = med
else:
l = med
if l != n // m:
print(r)
else:
print("-1")
``` | instruction | 0 | 95,301 | 10 | 190,602 |
Yes | output | 1 | 95,301 | 10 | 190,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
def r(a: int):
if a % 1 > 0.000000000000000001:
a += 1
return int(a)
n, m, k, L = map(int, input().split())
if L + k > n or m * r((L + k) / m) > n or m > n:
print(-1)
exit()
print(r((L + k) / m))
``` | instruction | 0 | 95,302 | 10 | 190,604 |
No | output | 1 | 95,302 | 10 | 190,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
n, m, k, l = (int(x) for x in input().split())
if l+k > n or m > n or m<1 or n<1 or k<1 or l<1:
print(-1)
else:
print((l+k+m-1)//m)
``` | instruction | 0 | 95,303 | 10 | 190,606 |
No | output | 1 | 95,303 | 10 | 190,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
from math import *
# t=int(input())
n,m,k,l=map(int,input().split(" "))
diff=n-m
if(diff<0):
print(-1)
exit()
diff=m
diff-=k
if(diff<l):
print(-1)
exit()
print(int(ceil(l/diff)))
``` | instruction | 0 | 95,304 | 10 | 190,608 |
No | output | 1 | 95,304 | 10 | 190,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:
* Everyone must gift as many coins as others.
* All coins given to Ivan must be different.
* Not less than L coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
Input
The only line of input contains 4 integers N, M, K, L (1 β€ K β€ N β€ 10^{18}; 1 β€ M, L β€ 10^{18}) β quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
Output
Print one number β minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
Examples
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
Submitted Solution:
```
import math
n,m,k,l=map(int,input().split())
if m>n:
print(-1)
else:
new=math.ceil((l+k)/m)
if new*m >n:
print(-1)
else:
print(new)
``` | instruction | 0 | 95,305 | 10 | 190,610 |
No | output | 1 | 95,305 | 10 | 190,611 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,573 | 10 | 191,146 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
# METO Bot 0.9.9
n,m,k=map(int,input().split())
if k<m<=k+n:
t=1
for i in range(k+1):
t*=(m-i)/(n+k-(i-1))
print(1-t)
else:
print(0 if m>n+k else 1)
# Made By Mostafa_Khaled
``` | output | 1 | 95,573 | 10 | 191,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,574 | 10 | 191,148 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
n,m,k = map(int,input().split())
if m >k and m <= n+k:
res= 1
for x in range(k+1):
res*=(m-x)/(n+k-(x-1))
print(1-res)
else:
print(0 if m > n+k else 1)
``` | output | 1 | 95,574 | 10 | 191,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,575 | 10 | 191,150 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
import sys
from array import array # noqa: F401
from math import log, e
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
if m <= k:
print(1)
exit()
if n + k < m:
print(0)
exit()
prob1 = 0.0
for i in range(m + n, m, -1):
prob1 += log(i)
for i in range(2, n + 1):
prob1 -= log(i)
prob2 = 0.0
for i in range(m + n, m - k - 1, -1):
prob2 += log(i)
for i in range(2, n + k + 2):
prob2 -= log(i)
print(1 - pow(e, prob2 - prob1))
``` | output | 1 | 95,575 | 10 | 191,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,576 | 10 | 191,152 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
def find(A):
n,m,k=A
if m<k:
return 1
temp1=1
temp2=1
for i in range(k+1):
temp1*=(m-i)
temp2*=(n+i+1)
return max(1-temp1/temp2,0)
print(find(list(map(int,input().strip().split(' ')))))
``` | output | 1 | 95,576 | 10 | 191,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,577 | 10 | 191,154 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
#!/usr/bin/python3.5
# -*- coding: utf-8 -*-
import json
import sys
def main():
n, m, k = map(int, input().strip().split())
if n + k < m:
print(0)
return
ans = 1.0
for i in range(k+1):
ans *= (m - i) * 1.0 / (n + i + 1)
print(1.0 - ans)
if __name__ == '__main__':
main()
``` | output | 1 | 95,577 | 10 | 191,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,578 | 10 | 191,156 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
n,m,k=map(int,input().split())
if k<m<=k+n:
t=1
for i in range(k+1):
t*=(m-i)/(n+k-(i-1))
print(1-t)
else:
print(0 if m>n+k else 1)
``` | output | 1 | 95,578 | 10 | 191,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,579 | 10 | 191,158 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
def main():
inp = input().split(" ")
n = (int)(inp[0])
m = (int)(inp[1])
k = (int)(inp[2])
if (m - n > k):
print(0)
elif (m <= k):
print(1)
else:
det = 1
num = 1
for i in range(m, m - k - 1, -1):
num *= i
for i in range(n + 1, n + k + 2, 1):
det *= i
print(1 - num / det)
main()
``` | output | 1 | 95,579 | 10 | 191,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0 | instruction | 0 | 95,580 | 10 | 191,160 |
Tags: combinatorics, math, probabilities
Correct Solution:
```
'''
Calculate the probability of m / (n + k) for each m and n
Print the 1 - the probability
'''
num10NotePeople, num20NotePeople, num10Notes = input().split()
num10NotePeople, num20NotePeople, num10Notes = int(num10NotePeople), int(num20NotePeople), int(num10Notes)
if num10Notes >= num20NotePeople:
print(1)
elif num20NotePeople > (num10NotePeople + num10Notes):
print(0)
else:
num = 1
den = 1
for i in range(num10Notes + 1):
num *= num20NotePeople - i
den *= num10NotePeople + i + 1
prob = 1 - num / den;
print(prob)
``` | output | 1 | 95,580 | 10 | 191,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0
Submitted Solution:
```
# METO Bot 0.9.9
n,m,k=map(int,input().split())
if k<m<=k+n:
t=1
for i in range(k+1):
t*=(m-i)/(n+k-(i-1))
print(1-t)
else:
print(0 if m>n+k else 1)
``` | instruction | 0 | 95,581 | 10 | 191,162 |
Yes | output | 1 | 95,581 | 10 | 191,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0
Submitted Solution:
```
n, m, k=map(int, input().split())
if k >= m:
print(1)
elif k < m <= k + n:
ans = 1
for i in range(k + 1):
ans *= (m - i) / (n + 1 + i)
print(1 - ans)
else:
print(0)
``` | instruction | 0 | 95,582 | 10 | 191,164 |
Yes | output | 1 | 95,582 | 10 | 191,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0
Submitted Solution:
```
def find(A):
n,m,k=A
if m<k:
return 1
temp1=1
temp2=1
for i in range(k+1):
temp1*=(m-i)
temp2*=(n+i+1)
return 1-temp1/temp2
print(find(list(map(int,input().strip().split(' ')))))
``` | instruction | 0 | 95,583 | 10 | 191,166 |
No | output | 1 | 95,583 | 10 | 191,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0
Submitted Solution:
```
n, m, k=map(int, input().split())
if k >= m:
print(1)
elif k < m <= k + n:
ans = 1
for i in range(k + 1):
ans *= (m - i) / (n + 1 + i)
print(1 - ans)
else:
print(1)
``` | instruction | 0 | 95,584 | 10 | 191,168 |
No | output | 1 | 95,584 | 10 | 191,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0
Submitted Solution:
```
num10NotePeople, num20NotePeople, num10Notes = input().split()
num10NotePeople, num20NotePeople, num10Notes = int(num10NotePeople), int(num20NotePeople), int(num10Notes)
num = 1
den = 1
for i in range(num10Notes + 1):
num *= num20NotePeople - i
den *= num10NotePeople + i + 1
prob = 1 - num / den;
print(prob)
``` | instruction | 0 | 95,585 | 10 | 191,170 |
No | output | 1 | 95,585 | 10 | 191,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for the race is 10 euros, so whenever someone comes to the ticket store only with 20 euro banknote Charlie must have a 10 euro banknote to give them change. Charlie realize that with the huge deficit of banknotes this could be a problem. Charlie has some priceless information but couldn't make use of it, so he needs your help. Exactly n + m people will come to buy a ticket. n of them will have only a single 10 euro banknote, and m of them will have only a single 20 euro banknote. Currently Charlie has k 10 euro banknotes, which he can use for change if needed. All n + m people will come to the ticket store in random order, all orders are equiprobable. Return the probability that the ticket selling process will run smoothly, i.e. Charlie will have change for every person with 20 euro banknote.
Input
The input consist of a single line with three space separated integers, n, m and k (0 β€ n, m β€ 105, 0 β€ k β€ 10).
Output
Output on a single line the desired probability with at least 4 digits after the decimal point.
Examples
Input
5 3 1
Output
0.857143
Input
0 5 5
Output
1
Input
0 1 0
Output
0
Submitted Solution:
```
n,m,k = map(int,input().split())
if m >k and m < n+k:
res= 1
for x in range(k+1):
res*=(m-x)/(n+k-(x-1))
print(1-res)
else:
print(0 if m > n+k else 1)
``` | instruction | 0 | 95,586 | 10 | 191,172 |
No | output | 1 | 95,586 | 10 | 191,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,052 | 10 | 194,104 |
Tags: data structures, greedy
Correct Solution:
```
R = lambda: map(int ,input().split())
n, k = R()
xs = list(R())
a = int(input())
cs = list(R())
r = j = 0
try:
for i, x in enumerate(xs):
if x > k:
while x > k:
s = min(cs[:i+1-j])
cs.remove(s)
r += s
j += 1
k += a
if x > k:
raise
except:
print(-1)
quit()
print(r)
``` | output | 1 | 97,052 | 10 | 194,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,053 | 10 | 194,106 |
Tags: data structures, greedy
Correct Solution:
```
import heapq
n,initial=map(int,input().split())
target=list(map(int,input().split()))
gain=int(input())
prices=list(map(int,input().split()))
flag=True
for i in range(n):
if target[i]>(i+1)*gain+initial:
flag=False
print(-1)
break
if flag:
a=[10**18]
heapq.heapify(a)
maxx=-1
ans=0
for i in range(n):
heapq.heappush(a,prices[i])
if target[i]>initial:
moves=(target[i] - initial - 1)//gain + 1
if moves==0:
break
else:
for i in range(moves):
ans+=heapq.heappop(a)
initial+=gain
print(ans)
``` | output | 1 | 97,053 | 10 | 194,107 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,054 | 10 | 194,108 |
Tags: data structures, greedy
Correct Solution:
```
import heapq
n,k=map(int,input().split())
des=list(map(int,input().split()))
g=int(input())
cost=list(map(int,input().split()))
cos=0
flag=0
cur=k
dec={}
hp=[]
heapq.heapify(hp)
for i in range(n):
dec[i]=0
for i in range(n):
if k+g*(i+1)<des[i]:
flag=1
break
else:
heapq.heappush(hp,cost[i])
while cur<des[i]:
cur+=g
cos+=heapq.heappop(hp)
if flag==1:
print(-1)
else:
print(cos)
``` | output | 1 | 97,054 | 10 | 194,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,055 | 10 | 194,110 |
Tags: data structures, greedy
Correct Solution:
```
import sys
import os
from io import BytesIO, IOBase
#########################
# imgur.com/Pkt7iIf.png #
#########################
# returns the list of prime numbers less than or equal to n:
'''def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r'''
# returns all the divisors of a number n(takes an additional parameter start):
'''def divs(n, start=1):
divisors = []
for i in range(start, int(n**.5) + 1):
if n % i == 0:
if n / i == i:
divisors.append(i)
else:
divisors.extend([i, n // i])
return len(divisors)'''
# returns the number of factors of a given number if a primes list is given:
'''def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
return divs_number'''
# returns the leftmost and rightmost positions of x in a given list d(if x isnot present then returns (-1,-1)):
'''def flin(d, x, default=-1):
left = right = -1
for i in range(len(d)):
if d[i] == x:
if left == -1: left = i
right = i
if left == -1:
return (default, default)
else:
return (left, right)'''
#count xor of numbers from 1 to n:
'''def xor1_n(n):
d={0:n,1:1,2:n+1,3:0}
return d[n&3]'''
def cel(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return defaultdict(int)
def ddl(): return defaultdict(list)
def ddd(): return defaultdict(defaultdict(int))
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from collections import defaultdict
#from collections import deque
#from collections import OrderedDict
#from math import gcd
#import time
#import itertools
#import timeit
#import random
#from bisect import bisect_left as bl
#from bisect import bisect_right as br
#from bisect import insort_left as il
#from bisect import insort_right as ir
from heapq import *
from queue import PriorityQueue
#mod=998244353
#mod=10**9+7
# for counting path pass prev as argument:
# for counting level of each node w.r.t to s pass lvl instead of prev:
n,k=mi()
X=li()
A=ii()
C=li()
ans=0
cost=[]
for i in range(n):
req=((X[i]-k)//A)+((X[i]-k)%A!=0)
heappush(cost,C[i])
if req>len(cost):
ans=-1
break
else:
for j in range(req):
ans+=heappop(cost)
k+=A
print(ans)
``` | output | 1 | 97,055 | 10 | 194,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,056 | 10 | 194,112 |
Tags: data structures, greedy
Correct Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify
def main():
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
for _ in range(1):
n,k=ria()
x=ria()
a=ri()
c=ria()
mcum=[]
heapmcum=heapify(mcum)
m=9999999999999999999999
spent=0
for i in range(n):
cost=0
heappush(mcum,c[i])
if k<x[i]:
while k<x[i]:
if len(mcum)==0:
spent=-1
break
cost+=heappop(mcum)
k+=a
if spent==-1:
break
spent+=cost
print(spent)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
``` | output | 1 | 97,056 | 10 | 194,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,057 | 10 | 194,114 |
Tags: data structures, greedy
Correct Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
def main():
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
for _ in range(1):
n,k=ria()
x=ria()
a=ri()
c=ria()
mcum=deque([])
m=9999999999999999999999
spent=0
for i in range(n):
cost=0
mcum.append(c[i])
mcum=deque(sorted(mcum))
if k<x[i]:
while k<x[i]:
if len(mcum)==0:
spent=-1
break
cost+=mcum[0]
mcum.popleft()
k+=a
if spent==-1:
break
spent+=cost
print(spent)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
``` | output | 1 | 97,057 | 10 | 194,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,058 | 10 | 194,116 |
Tags: data structures, greedy
Correct Solution:
```
from math import ceil
from heapq import heappush, heapify, heappop
n,x = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
a = int(input())
c = [int(i) for i in input().split()]
for i in range(n):
l[i] = ceil((l[i]-x)/a)
# print(l)
cost = 0
flag = True
heap = []
till = 0
for i in range(n):
heappush(heap,c[i])
# if l[i]>len(heap):
l[i] = max(l[i]-till, 0)
while(l[i]>0 and heap):
k = heappop(heap)
cost+=k
l[i]-=1
till+=1
if l[i]>0:
flag = False
break
if flag:
print(cost)
else:
print(-1)
``` | output | 1 | 97,058 | 10 | 194,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2. | instruction | 0 | 97,059 | 10 | 194,118 |
Tags: data structures, greedy
Correct Solution:
```
import heapq
def process(n, k, X, a, C):
res=0
A=[]
for i in range(len(X)):
heapq.heappush(A, C[i])
if k+len(A)*a < X[i]:
return -1
else:
while k <X[i]:
res+=heapq.heappop(A)
k+=a
return res
n, k=[int(x) for x in input().split()]
X=[int(x) for x in input().split()]
a=int(input())
C=[int(x) for x in input().split()]
print(process(n,k,X,a,C))
``` | output | 1 | 97,059 | 10 | 194,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
import heapq
n,k=map(int,input().split())
lis=list(map(int,input().split()))
energy=int(input())
cost=list(map(int,input().split()))
h=[]
length=len(lis)
output=0
for i in range(length):
heapq.heappush(h,cost[i])
if lis[i]>k:
while(h):
if k>=lis[i]:
break
output+=heapq.heappop(h)
k+=energy
if k<lis[i]:
print(-1)
break
else:
print(output)
``` | instruction | 0 | 97,060 | 10 | 194,120 |
Yes | output | 1 | 97,060 | 10 | 194,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
import heapq as hp
import sys
n, k = map(int, input().split())
arr = list(map(int, input().split()))
p = int(input())
arrx = list(map(int, input().split()))
prev = []
hp.heapify(prev)
cost = 0
flag = 0
for i in range(n):
hp.heappush(prev, arrx[i])
while arr[i] > k and len(prev) > 0:
k += p
cost += hp.heappop(prev)
if k < arr[i]:
flag = 1
break
if flag == 1:
print(-1)
else:
print(cost)
``` | instruction | 0 | 97,061 | 10 | 194,122 |
Yes | output | 1 | 97,061 | 10 | 194,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
n, k = map(int, input().split())
P = list(map(int, input().split()))
from heapq import *
A = int(input())
c = list(map(int, input().split()))
cur = []
cost = 0
for i, p in enumerate(P):
heappush(cur, c[i])
if p > k:
if len(cur)*A + k < p:
cost = -1
break
else:
while p > k:
cost += heappop(cur)
k += A
print(cost)
``` | instruction | 0 | 97,062 | 10 | 194,124 |
Yes | output | 1 | 97,062 | 10 | 194,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
N,K = map(int,input().split())
X = list(map(int,input().split()))
A = int(input())
C = list(map(int,input().split()))
available_drinks = []
total_cost = 0
ability = K
for i in range(N):
available_drinks.append(C[i])
if ability < X[i]:
drinks_needed = (X[i] - ability - 1) // A + 1
if drinks_needed > len(available_drinks):
print(-1)
break
available_drinks.sort()
total_cost += sum(available_drinks[:drinks_needed])
available_drinks = available_drinks[drinks_needed:]
ability += A * drinks_needed
else:
print(total_cost)
``` | instruction | 0 | 97,063 | 10 | 194,126 |
Yes | output | 1 | 97,063 | 10 | 194,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
import heapq
import math
n,k = list(map(int,input().split()))
x = list(map(int,input().split()))
a = int(input())
c = list(map(int,input().split()))
maxx = max(x)
fx = x.index(maxx)
delta = maxx-k
if delta<=0:
print(0)
elif delta/(fx+1) > a:
print(-1)
else:
v = math.ceil(delta/a)
x = x[:fx+1]
c = c[:fx+1]
out = 0
x1 = x[:]
for i in range(fx-1,-1,-1):
x1[i]=max(x[i],x1[i+1]-a)
minv = []
for i in range(fx+1):
heapq.heappush(minv,c[i])
if k<x1[i]:
k+=a
out += heapq.heappop(minv)
print(out)
``` | instruction | 0 | 97,064 | 10 | 194,128 |
No | output | 1 | 97,064 | 10 | 194,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
import sys, math
input = lambda: sys.stdin.readline().strip("\r\n")
n, k = map(int, input().split())
x = list(map(int, input().split()))
a = int(input())
c = list(map(int, input().split()))
ans = 0
left = []
ref = k
if k + a < x[0]:
print(-1)
exit()
elif k + a == x[0]:
ans += c[0]
k += a
for i in range(n-1):
if ref <= x[i + 1] - k <= ref + a:
k += a
ans += c[i+1]
elif x[i+1] - k < 0:
continue
elif 0 <= x[i+1] - k <= ref:
left.append(i+1)
else:
if len(left) > 0 and x[i+1] - k <= a * len(left):
req = math.ceil((x[i] - k) / a)
if req <= len(left):
left.sort()
# k += left[:req]
for i in range(req):
k += left[i]
ans += c[left[i]]
else:
print(-1)
exit()
else:
print(-1)
exit()
print(ans)
``` | instruction | 0 | 97,065 | 10 | 194,130 |
No | output | 1 | 97,065 | 10 | 194,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
# from debug import debug
import sys;input = sys.stdin.readline
n, k = map(int, input().split())
lis = list(map(int, input().split()))
a = int(input())
c = list(map(int, input().split()))
cost = 0
for j, i in enumerate(lis):
if i>k:
if i>k+a:
print(-1); sys.exit()
cost += c[j]
k+=a
print(cost)
``` | instruction | 0 | 97,066 | 10 | 194,132 |
No | output | 1 | 97,066 | 10 | 194,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift X[i] grams on day i. In order to improve his workout performance at the gym, he can buy exactly one pre-workout drink at the gym he is currently in and it will improve his performance by A grams permanently and immediately. In different gyms these pre-workout drinks can cost different amounts C[i] because of the taste and the gym's location but its permanent workout gains are the same. Before the first day of starting his workout plan, Alan knows he can lift a maximum of K grams. Help Alan spend a minimum total amount of money in order to reach his workout plan. If there is no way for him to complete his workout plan successfully output -1.
Input
The first one contains two integer numbers, integers N (1 β€ N β€ 10^5) and K (1 β€ K β€ 10^5) β representing number of days in the workout plan and how many grams he can lift before starting his workout plan respectively. The second line contains N integer numbers X[i] (1 β€ X[i] β€ 10^9) separated by a single space representing how many grams Alan wants to lift on day i. The third line contains one integer number A (1 β€ A β€ 10^9) representing permanent performance gains from a single drink. The last line contains N integer numbers C[i] (1 β€ C[i] β€ 10^9) , representing cost of performance booster drink in the gym he visits on day i.
Output
One integer number representing minimal money spent to finish his workout plan. If he cannot finish his workout plan, output -1.
Examples
Input
5 10000
10000 30000 30000 40000 20000
20000
5 2 8 3 6
Output
5
Input
5 10000
10000 40000 30000 30000 20000
10000
5 2 8 3 6
Output
-1
Note
First example: After buying drinks on days 2 and 4 Alan can finish his workout plan. Second example: Alan cannot lift 40000 grams on day 2.
Submitted Solution:
```
import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
stdin, stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def ceil(a, b): return (a+b-1)//b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
n, k = mp()
arr = lmp()
a = iinp()
cost = lmp()
hp = []
ans = 0
flg = True
for i in range(n):
if k >= arr[i]:
heappush(hp, cost[i])
else:
while hp and k < arr[i]:
k += a
ans += heappop(hp)
if k < arr[i]:
flg = False
break
print(ans if flg else -1)
``` | instruction | 0 | 97,067 | 10 | 194,134 |
No | output | 1 | 97,067 | 10 | 194,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xjΒ·k for 1 β€ j β€ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.
Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?
Input
The first line contains two integers n and S (1 β€ n β€ 105 and 1 β€ S β€ 109) β the number of souvenirs in the market and Sagheer's budget.
The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 105) β the base costs of the souvenirs.
Output
On a single line, print two integers k, T β the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.
Examples
Input
3 11
2 3 5
Output
2 11
Input
4 100
1 2 5 6
Output
4 54
Input
1 7
7
Output
0 0
Note
In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | instruction | 0 | 97,530 | 10 | 195,060 |
Tags: binary search, sortings
Correct Solution:
```
n,s=[int(i) for i in input().split()]
ll=[int(i) for i in input().split()]
curr=0;
l=0
h=n
while l<=h :
mid = (h+l)//2;
k=ll[:]
for i in range(n):k[i]=(i+1)*mid+ll[i];
k.sort();
#print(k)
sm=sum(k[:mid])
#print(mid,sm)
if sm<=s:
curr=mid
l=mid+1
ans=sm
else:
h=mid-1
print(curr,ans)
``` | output | 1 | 97,530 | 10 | 195,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xjΒ·k for 1 β€ j β€ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.
Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?
Input
The first line contains two integers n and S (1 β€ n β€ 105 and 1 β€ S β€ 109) β the number of souvenirs in the market and Sagheer's budget.
The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 105) β the base costs of the souvenirs.
Output
On a single line, print two integers k, T β the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.
Examples
Input
3 11
2 3 5
Output
2 11
Input
4 100
1 2 5 6
Output
4 54
Input
1 7
7
Output
0 0
Note
In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | instruction | 0 | 97,531 | 10 | 195,062 |
Tags: binary search, sortings
Correct Solution:
```
n ,mm = list(map(int, input().split()))
ar = list(map(int, input().split()))
pr = list(ar)
def check(curr):
for i in range(0,n):
pr[i] = ar[i] + curr*(i+1)
pr.sort()
ans=0
for i in range(0, curr):
ans = ans + pr[i]
return ans
def BS(l,r):
if r==l+1 :
if check(r)<=mm:
return r
return l
m = l+r
m = m//2
if check(m)<=mm:
return BS(m,r)
return BS(l,m)
ans = BS(0,n)
print(ans,end = ' ')
print(check(ans))
``` | output | 1 | 97,531 | 10 | 195,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xjΒ·k for 1 β€ j β€ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.
Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?
Input
The first line contains two integers n and S (1 β€ n β€ 105 and 1 β€ S β€ 109) β the number of souvenirs in the market and Sagheer's budget.
The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 105) β the base costs of the souvenirs.
Output
On a single line, print two integers k, T β the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.
Examples
Input
3 11
2 3 5
Output
2 11
Input
4 100
1 2 5 6
Output
4 54
Input
1 7
7
Output
0 0
Note
In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | instruction | 0 | 97,532 | 10 | 195,064 |
Tags: binary search, sortings
Correct Solution:
```
def check(li,mid,c):
s = []
for i in range(len(li)):
s.append(li[i] + mid*(i+1))
s.sort()
x = 0
for i in range(mid):
x += s[i]
if x > c:
return False,x
return True,x
def main(li,c):
start = 0
end = len(li)
ans = -1
sol = -1
while start<=end:
mid = (start+end)//2
z,y = check(li,mid,c)
if z == True:
ans = mid
sol = y
start = mid+1
else:
end = mid-1
print(ans,sol)
n,c = [int(x) for x in input().split()]
li = [int(x) for x in input().split()]
main(li,c)
``` | output | 1 | 97,532 | 10 | 195,065 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xjΒ·k for 1 β€ j β€ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.
Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?
Input
The first line contains two integers n and S (1 β€ n β€ 105 and 1 β€ S β€ 109) β the number of souvenirs in the market and Sagheer's budget.
The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 105) β the base costs of the souvenirs.
Output
On a single line, print two integers k, T β the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.
Examples
Input
3 11
2 3 5
Output
2 11
Input
4 100
1 2 5 6
Output
4 54
Input
1 7
7
Output
0 0
Note
In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | instruction | 0 | 97,533 | 10 | 195,066 |
Tags: binary search, sortings
Correct Solution:
```
#!/usr/bin/python3
cost = 0
n, s = map(int, input().split())
a = list(map(int, input().split()))
def funcMonotonic(a, s, k):
global cost
costs = [a[i] + (i + 1) * k for i in range(n)]
costs.sort()
cost = sum(costs[:k])
return cost <= s
left, right = 0, n + 1
while left + 1 < right:
middle = (left + right) // 2
if funcMonotonic(a, s, middle):
left = middle
else:
right = middle
funcMonotonic(a, s, left)
print(left, cost)
``` | output | 1 | 97,533 | 10 | 195,067 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.