message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There is one bar-shaped candy with a length of N mm (where N is an even number). Two JOI officials decided to cut this candy into multiple pieces and divide them into a total of N / 2 mm. did.
For unknown reasons, this candy has different ease of cutting depending on the location. The two examined the candy every millimeter from the left and figured out how many seconds it would take to cut at each location. .2 Create a program that finds the minimum number of seconds it takes for a person to cut a candy.
output
The output consists of one line containing the minimum number of seconds it takes for two people to cut the candy.
Input / output example
Input example 1
6
1
8
12
6
2
Output example 1
7
In this case, cutting 1 and 4 millimeters from the left edge minimizes the number of seconds. The number of seconds is 1 and 6 seconds, for a total of 7 seconds.
<image>
The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.
input
The length of the bar N (2 ≤ N ≤ 10000, where N is an even number) is written on the first line of the input. On the first line of the input i + (1 ≤ i ≤ N − 1), An integer ti (1 ≤ ti ≤ 10000) is written to represent the number of seconds it takes to cut the i-millimeter location from the left edge. Note that there are N − 1 locations that can be cut.
Of the scoring data, the minimum value can be achieved by cutting at most 2 points for 5% of the points, and the minimum value can be achieved by cutting at most 3 points for 10%. For 20% of the points, N ≤ 20.
Example
Input
6
1
8
12
6
2
Output
7
Submitted Solution:
```
dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
a=int(input())
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2])
exit()
``` | instruction | 0 | 6,528 | 9 | 13,056 |
No | output | 1 | 6,528 | 9 | 13,057 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,491 | 9 | 14,982 |
"Correct Solution:
```
n,p,q = map(int,input().split())
cn=[]
for i in range(n):
cn.append(int(input()))
difs=[p*(q-i)-cn[i] for i in range(n)]
difs=sorted(difs, reverse=True)
ans=[sum(cn)]
for i in range(n):
ans.append(ans[-1]+2*i*p+difs[i])
print(max(ans))
``` | output | 1 | 7,491 | 9 | 14,983 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,492 | 9 | 14,984 |
"Correct Solution:
```
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
N, P, Q = map(int, readline().split())
*C, = [int(readline()) for i in range(N)]
A = [0]*N
su = sum(C)
for i in range(N):
A[i] = P*(Q-i) - C[i]
A.sort(reverse=1)
ans = su
for i in range(N):
su += A[i]
ans = max(ans, su + P*i*(i+1))
write("%d\n" % ans)
solve()
``` | output | 1 | 7,492 | 9 | 14,985 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,493 | 9 | 14,986 |
"Correct Solution:
```
n,p,q = map(int, input().split())
cn = []
for i in range(n):
cn.append(int(input()))
difs = [p*(q-i) - cn[i] for i in range(n)] ##0번째 자취에서 1번 i번째날 자취할 때의 증가분
difs = sorted(difs, reverse = True) ##제일 증가분이 큰 순서대로 sort
ans = [sum(cn)] ##(ans[i] = i번 자취시 행복도의 최대값) 으로 만들것임
for i in range(n):
ans.append(ans[-1] + 2*i*p + difs[i])
##i=0에서는 자취를 한번만 한 것으로 자취파워가 올라간 것을 반영한 2ip는 0이 된다.
##(자취파워 올라간게 반영되지 않으므로)
print(max(ans)) ##0~n번 자취할때 의 최대값들중 최대값을 출력.
``` | output | 1 | 7,493 | 9 | 14,987 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,494 | 9 | 14,988 |
"Correct Solution:
```
INF = 10 ** 15
MOD = 10 ** 9 + 7
def main():
N,P,Q = map(int,input().split())
C = [int(input()) for _ in range(N)]
ret = sum(C)
C = [c + P*i for i,c in enumerate(C)]
C.sort()
x = 0
ans = ret
for i in range(N):
ret += -C[i] + P*(2*x + Q)
ans = max(ans,ret)
x += 1
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 7,494 | 9 | 14,989 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,495 | 9 | 14,990 |
"Correct Solution:
```
#着席位置は中央*奥
#問題は「Dinner」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2642&lang=jp)
#方針としては、自炊をする回数(0~n)を決め打ちし、それぞれの時の最大値を計算してその最大値を返すことにする
#n回自炊するとき、自炊パワーはn-1回自壊する時に比べ最終的に2増える。
#これを考えると、n回自炊する時、高まる自炊パワーによる幸福度の増加分はn*(n+1)となる
#したがって、まずリストdifsに「自炊と食堂の幸福度の差分」を全て入れる
#これを降順にソートし、n回自炊した時の幸福度の最大値をansに入れていく
#ansの最大値を出力して、終了
n,p,q = map(int,input().split())
cs = []
for i in range(n):
cs.append(int(input()))
ans = [sum(cs)]
difs = [p * (q-i) - cs[i] for i in range(n)]
difs.sort(reverse = True)
for i in range(n):
ans.append(ans[-1] + 2 * i * p + difs[i])
print(max(ans))
``` | output | 1 | 7,495 | 9 | 14,991 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,496 | 9 | 14,992 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n, p, q = LI()
c = [I() for _ in range(n)]
s = sum(c)
a = sorted([[c[i]+p*i, i] for i in range(n)])
r = s
for i in range(n):
s -= c[a[i][1]] + p * a[i][1]
t = s + p*i*(i+1) + p*q*(i+1)
if t > r:
r = t
return r
print(main())
``` | output | 1 | 7,496 | 9 | 14,993 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,497 | 9 | 14,994 |
"Correct Solution:
```
n,p,q=map(int,input().split())
b=[0]*n
for i in range(n):b[i]=p*i+int(input())
b.sort()
a=q*p*n+p*n*~-n//2;s=0
for i in range(1,-~n):
s+=b[n-i]
a=max(a,p*q*(n-i)+p*(n-i)*(~-n-i)//2-p*i*(i-1)//2-p*i*(n-i)+s)
print(a)
``` | output | 1 | 7,497 | 9 | 14,995 |
Provide a correct Python 3 solution for this coding contest problem.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27 | instruction | 0 | 7,498 | 9 | 14,996 |
"Correct Solution:
```
#演習2-18
def solve(N,P,Q,menu):
all_happy = [P*(Q-i) - menu[i] for i in range(N)]
all_happy = sorted(all_happy, reverse = True)
happy = [sum(menu)]
for i in range(N):
happy.append(happy[-1] + P*i*2 + all_happy[i])
return(max(happy))
while True:
try:
N,P,Q = map(int,input().split())
menu = []
for i in range(N):
menu.append(int(input()))
print(solve(N,P,Q,menu))
except:
break
``` | output | 1 | 7,498 | 9 | 14,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27
Submitted Solution:
```
tmp = list(map(int,input().split()))
n,p,q = tmp[0],tmp[1],tmp[2]
cs = []
for i in range(n):
cs.append(int(input()))
ans = [sum(cs)]
difs = [p * (q-i) - cs[i] for i in range(n)]
difs.sort(reverse = True)
for i in range(n):
ans.append(ans[-1] + 2 * i * p + difs[i])
print(max(ans))
``` | instruction | 0 | 7,499 | 9 | 14,998 |
Yes | output | 1 | 7,499 | 9 | 14,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the spring of 2014, a student successfully passed the university and started living alone. The problem here is what to do with the supper. He decided to plan a supper for the next N days.
He wants to maximize the total happiness he gets in N days. Of course, the more delicious or favorite you eat, the higher your happiness.
His dinner options are two, either head to a nearby dining room or cook for himself.
The happiness you get in the cafeteria depends on the menu of the day. The menu changes daily, but there is only one type every day, and all the menus for N days have already been released. So he knows all the information that if you go to the cafeteria on day i (1 ≤ i ≤ N) you will get the happiness of Ci.
The happiness obtained by self-catering is the self-catering power at the start of self-catering multiplied by a constant P. The initial value of self-catering power is Q, which is -1 if you go to the restaurant every day, +1 if you cook yourself, and fluctuates at the end of the meal of the day.
Find the maximum sum of happiness for him.
Constraints
* 1 ≤ N ≤ 500,000
* 0 ≤ P ≤ 500,000
* | Q | ≤ 500,000
* | Ci | ≤ 500,000
Input
The input is given in the following format as N + 1 line.
N P Q
C1
C2
::
CN
* The first line is given three integers N, P, and Q, which are the number of days, the constant for calculating the happiness of self-catering, and the initial value of self-catering power.
* From the 2nd line to the N + 1st line, one integer is given, and the i + 1st line gives the happiness obtained when going to the cafeteria on the i day.
Output
Output the maximum value of happiness that can be taken in one line.
Examples
Input
1 1 1
2
Output
2
Input
3 2 1
3
3
3
Output
12
Input
3 1 -1
2
-3
2
Output
2
Input
3 1 -10
-10
-10
-10
Output
-27
Submitted Solution:
```
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n,p,q = LI()
c = IR(n)
cp = [c[i]+p*i for i in range(n)]
cp.sort(reverse=True)
ans = 0
s = 0
for i in range(n):
s += cp[i]
ns = s+p*(i+1)*(i+2-(q+2*n))
if ans < ns:
ans = ns
print(ans+p*(n*q+(n*(n-1))//2))
return
#Solve
if __name__ == "__main__":
solve()
``` | instruction | 0 | 7,500 | 9 | 15,000 |
Yes | output | 1 | 7,500 | 9 | 15,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,687 | 9 | 15,374 |
Tags: math
Correct Solution:
```
n=int(input())
for i in range(n):
a,b=map(int,input().split())
print(min(a%b,b//2)+a//b*b)
``` | output | 1 | 7,687 | 9 | 15,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,688 | 9 | 15,376 |
Tags: math
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 30 15:51:28 2019
@author: 20122
"""
a = int(input())
candy = []
for i in range(a):
k = input()
k = k.split()
candy.append([int(k[0]), int(k[1])])
for i in range(len(candy)):
num = candy[i][0] - (candy[i][0] % candy[i][1]) + min(candy[i][0] % candy[i][1], int(candy[i][1] / 2))
print(num)
``` | output | 1 | 7,688 | 9 | 15,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,689 | 9 | 15,378 |
Tags: math
Correct Solution:
```
n = int(input())
lst = []
for i in range(n):
lst.append(list(map(int, input().split())))
for i in lst:
if i[0] % i[1] > i[1] // 2:
print(i[0] // i[1] * i[1] + i[1] // 2)
else:
print(i[0] // i[1] * i[1] + i[0] % i[1])
``` | output | 1 | 7,689 | 9 | 15,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,690 | 9 | 15,380 |
Tags: math
Correct Solution:
```
for t in range(int(input())):
n, k = (int(i) for i in input().split())
print(min(n//k*k+k//2, n))
``` | output | 1 | 7,690 | 9 | 15,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,691 | 9 | 15,382 |
Tags: math
Correct Solution:
```
import math
test = int(input())
while(test):
candies, kids = map(int, input().split(' '))
canuse = 0
canuse = ((candies//kids)*kids)
remaining = candies % kids
if (remaining > 0):
floor = math.floor(kids/2)
if (remaining <= floor):
canuse+=remaining
else:
canuse+=floor
print(canuse)
test-=1
``` | output | 1 | 7,691 | 9 | 15,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,692 | 9 | 15,384 |
Tags: math
Correct Solution:
```
for t in range(int(input())):
n, k = map(int, input().split())
full = n - n % k
full += min(n % k, k // 2)
print(full)
``` | output | 1 | 7,692 | 9 | 15,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,693 | 9 | 15,386 |
Tags: math
Correct Solution:
```
q = int(input())
for _ in range(q):
n, k = map(int, input().split())
full = n - n % k
full += min(n % k, k // 2)
print(full)
``` | output | 1 | 7,693 | 9 | 15,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies. | instruction | 0 | 7,694 | 9 | 15,388 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
a,b = map(int,input().split())
tot = (a//b)*b
rem = a-tot
r = b//2
if( rem >= b//2):
tot += b//2
else:
tot += rem
print(tot)
``` | output | 1 | 7,694 | 9 | 15,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
t = int(input())
for i in range (t):
n, k = list(map(int,input().split()))
m = n % k
print(n - m + min(k//2, m) )
``` | instruction | 0 | 7,695 | 9 | 15,390 |
Yes | output | 1 | 7,695 | 9 | 15,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
t = int(input())
for i in range(t):
n, k = map(int, input().split())
mod = n%k
if mod == 0:
print(n)
else:
print(n-mod + min(k//2, mod))
``` | instruction | 0 | 7,696 | 9 | 15,392 |
Yes | output | 1 | 7,696 | 9 | 15,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
for i in range(int(input())):
n,k=map(int,input().split())
candies=int(n/k)*k
n-=candies
if n>int(k/2):
candies+=int(k/2)
else:
candies+=n
print(candies)
``` | instruction | 0 | 7,697 | 9 | 15,394 |
Yes | output | 1 | 7,697 | 9 | 15,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
import math
t = int(input())
for i in range(t):
n,k = map(int,input().split())
down = math.floor(k/2)
cand = math.floor(n/k)
if(down*(cand+1) + ((k-down)*cand) <= n):
print(down*(cand+1) + ((k-down)*cand))
else:
print(n)
``` | instruction | 0 | 7,698 | 9 | 15,396 |
Yes | output | 1 | 7,698 | 9 | 15,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
# candie.division.py
for i in range(int(input())):
n,k = map(int,input().split())
if n<=k:
print(n)
else:
if n%k == 0:
print(n)
else:
x = n//k
y = x+1
p = k//2
k = k-p
ans = 0
ans += y*p
ans += k*x
print(ans)
``` | instruction | 0 | 7,699 | 9 | 15,398 |
No | output | 1 | 7,699 | 9 | 15,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
t=int(input())
for _ in range(t):
#print(_)
n,k=map(int,input().split())
l=[]
d=n%k
d1=n//k
half=k//2
sum=0
sum1=0
for i in range(k):
l.append(d1)
#print(l)
for i in l:
sum+=i
#print(sum)
if(sum==n):
print(n)
break
else:
for i in range(half):
l[i]+=1
#print(l)
for i in l:
sum1+=i
print(sum1)
``` | instruction | 0 | 7,700 | 9 | 15,400 |
No | output | 1 | 7,700 | 9 | 15,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
import math
t=int(input())
for i in range(t):
n,k=map(int, input().split())
a=math.floor(n/k)
n1=n
s1=0
a_count=0
b_count=1
b=a
if (a>0):
a_count=k-math.floor(k/2)
b_count=k-a_count
else:
a_count=0
b_count=1
if (n>=(a*a_count+b*b_count)):
s=a*a_count+b*b_count
a_count=0
b_count=1
b=a+1
n1=n
if (a>0):
a_count=k-math.floor(k/2)
b_count=k-a_count
else:
a_count=0
b_count=1
if (n>=(a*a_count+b*b_count)):
s1=a*a_count+b*b_count
if(s>s1):
print(s)
else:
print(s1)
``` | instruction | 0 | 7,701 | 9 | 15,402 |
No | output | 1 | 7,701 | 9 | 15,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:
* b - a ≤ 1 (it means b = a or b = a + 1);
* the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).
⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.
Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases.
The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.
Output
For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.
Example
Input
5
5 2
19 4
12 7
6 2
100000 50010
Output
5
18
10
6
75015
Note
In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.
In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.
In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.
In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.
Submitted Solution:
```
import sys; import math;
CASE=0; rla=''
def solve() :
s=str(input())
print(len(s)+1)
while True :
rla=sys.stdin.readline()
cases=1
if not rla: break
if (rla=='\n')|(rla=='') : continue
if CASE==1 : cases=int(rla)
for cas in range(cases) :
solve()
``` | instruction | 0 | 7,702 | 9 | 15,404 |
No | output | 1 | 7,702 | 9 | 15,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,884 | 9 | 15,768 |
Tags: greedy, implementation
Correct Solution:
```
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
s=0
for i in range(n):
if a[i]==1:
if m!=0:
m-=1
else:
s+=1
else:
if k!=0:
k-=1
elif m!=0:
m-=1
else:
s+=1
print(s)
``` | output | 1 | 7,884 | 9 | 15,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,885 | 9 | 15,770 |
Tags: greedy, implementation
Correct Solution:
```
n, m, k = list(map(int, input().split()))
a = input().split()
counter = 0
for i in range(n):
if(a[i] == "1"):
m -= 1
else:
if(k != 0):
k -= 1
else:
m -= 1
if(m < 0):
washM = abs(m)
else:
washM = 0
if(k < 0):
washK = abs(k)
else:
washK = 0
counter = washM + washK
print(counter)
``` | output | 1 | 7,885 | 9 | 15,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,886 | 9 | 15,772 |
Tags: greedy, implementation
Correct Solution:
```
n, m, k = map(int, input().split())
a = [int(e) for e in input().split()]
ans = 0
for i in a:
if i == 2 and k > 0:
k -= 1
elif m > 0:
m -= 1
else:
ans += 1
print(ans)
``` | output | 1 | 7,886 | 9 | 15,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,887 | 9 | 15,774 |
Tags: greedy, implementation
Correct Solution:
```
s=input().split()
n=int(s[0])
bowl=int(s[1])
plate=int(s[2])
s=input().split()
a=0
b=0
for i in s:
if i=='1':
a+=1
if i=='2':
b+=1
kq=0
if a>bowl:
kq=a-bowl
bowl=0
else: bowl=bowl-a
if b>plate+bowl: kq+=b-(plate+bowl)
print(kq)
``` | output | 1 | 7,887 | 9 | 15,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,888 | 9 | 15,776 |
Tags: greedy, implementation
Correct Solution:
```
n, b, p = input().split()
n = int(n)
b = int(b)
p = int(p)
arr = input().split()
for a in range(len(arr)):
if arr[a] == "1" :
b -= 1
else :
p -= 1
if p < 0 :
b -= abs(p)
result = abs(b)
if b > 0 : result = 0
print(result)
``` | output | 1 | 7,888 | 9 | 15,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,889 | 9 | 15,778 |
Tags: greedy, implementation
Correct Solution:
```
ar = list(map(int,input().split(' ')))
n = ar[0]
m = ar[1]
k = ar[2]
array = list(map(int,input().split(' ')))
for i in array:
if i==1:
m-=1
else:
if k > 0:
k -= 1
else:
m -= 1
res = 0
res += -m if m<0 else 0
res += -k if k<0 else 0
print(res)
``` | output | 1 | 7,889 | 9 | 15,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,890 | 9 | 15,780 |
Tags: greedy, implementation
Correct Solution:
```
n, m, k = map(int, input().split())
dishes= list(map(int, input().split()))
answer=0
for i in dishes:
if i==1:
m = m-1
if m<0:
answer = answer +1
if i==2:
if k>0:
k = k-1
elif m>0:
m = m-1
else:
answer = answer+1
print(answer)
``` | output | 1 | 7,890 | 9 | 15,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | instruction | 0 | 7,891 | 9 | 15,782 |
Tags: greedy, implementation
Correct Solution:
```
n,m,k=list(map(int,input().split()))
t=list(map(int,input().split()))
if 2 not in t:
r=sum(t)
if m>=r:
print(0)
else:
print(abs(r-m))
elif 1 not in t:
if m+k >= n:
print(0)
else:
print(abs(m+k-n))
else:
a=t.count(1)
b=t.count(2)
p=0
if m>= a:
k+= m-a
else:
p+=a-m
if k >= b:
pass
else:
p+=b-k
print(abs(p))
``` | output | 1 | 7,891 | 9 | 15,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
n, b, p = map(int, input().split())
meals = list(map(int, input().split()))
x = meals.count(1)
y = meals.count(2)
b -= x
if b >= 0:
p += b
p -= y
count = 0
if b < 0:
count+=b
if p < 0:
count+=p
print(abs(count))
``` | instruction | 0 | 7,892 | 9 | 15,784 |
Yes | output | 1 | 7,892 | 9 | 15,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for a in A:
if a == 1:
if m > 0:
m -= 1
else:
ans += 1
elif a == 2:
if k > 0:
k -= 1
else:
if m > 0:
m -= 1
else:
ans += 1
print(ans)
``` | instruction | 0 | 7,893 | 9 | 15,786 |
Yes | output | 1 | 7,893 | 9 | 15,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
n, m, k = map(int, input().split())
l_d = list(map(int, input().split()))
t = 0
for d in l_d:
if d == 2:
if k > 0:
k -= 1
else:
if m > 0:
m -= 1
else:
t += 1
else:
if m > 0:
m -= 1
else:
t += 1
print(t)
``` | instruction | 0 | 7,894 | 9 | 15,788 |
Yes | output | 1 | 7,894 | 9 | 15,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
n, m, k = map(int, input().split())
b1 = len([0 for i in input().split() if i == '1'])
b2 = n - b1
print (max(0, b1 - m + max(0, b2 - k)))
``` | instruction | 0 | 7,895 | 9 | 15,790 |
Yes | output | 1 | 7,895 | 9 | 15,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
n,m,k = map(int, input().split())
mmax = m
kmax = k
ris = 0
types = list(map(int, input().split()))
for p in types:
if p == 2:
if m != 0:
m -= 1
elif k !=0:
k -= 1
else:
ris += 1
else:
if m!=0:
m -= 1
else:
ris += 1
print(ris)
``` | instruction | 0 | 7,896 | 9 | 15,792 |
No | output | 1 | 7,896 | 9 | 15,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
def main(stdin):
n, m, k = next(stdin).split()
n, m, k = int(n), int(m), int(k)
for a in next(stdin).split():
if int(a) == 1:
m -= 1
if int(a) == 2:
k -= 1
t = 0
if m < 0: t += m * (-1)
if k < 0: t += k * (-1)
print(t)
if __name__ == '__main__':
import sys
main(sys.stdin)
``` | instruction | 0 | 7,897 | 9 | 15,794 |
No | output | 1 | 7,897 | 9 | 15,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
days, usual_cl, flat_cl = input().split()
usual = 0
flat = 0
dish = input()
dish_list = (dish.split())
for i in dish_list:
if i == '1':
usual+=1
else:
flat+=1
usual = int(usual)-int(usual_cl)
flat = int(flat)-int(flat_cl)
if '1' and '2' in dish_list:
print(flat+usual)
else:
if '1' in dish_list and not '2' in dish_list:
print(usual)
else:
print(flat)
``` | instruction | 0 | 7,898 | 9 | 15,796 |
No | output | 1 | 7,898 | 9 | 15,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input
The first line of the input contains three integers n, m, k (1 ≤ n, m, k ≤ 1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 2). If ai equals one, then on day i Valera will eat a first type dish. If ai equals two, then on day i Valera will eat a second type dish.
Output
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Examples
Input
3 1 1
1 2 1
Output
1
Input
4 3 1
1 1 1 1
Output
1
Input
3 1 2
2 2 2
Output
0
Input
8 2 2
1 2 1 2 1 2 1 2
Output
4
Note
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
Submitted Solution:
```
inp = input().split(' ')
dishes = input().split(' ')
days = int(inp[0])
bowls = int(inp[1])
plates = int(inp[2])
shouldWash = 0
for i in dishes:
days -= 1
if days < 0:
break
if i == '1':
bowls -= 1
else:
if plates <= 0:
bowls -= 1
else:
plates -= 1
if bowls < 0 or plates < 0:
shouldWash += 1
print(shouldWash)
``` | instruction | 0 | 7,899 | 9 | 15,798 |
No | output | 1 | 7,899 | 9 | 15,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it exactly at the date written on the carton). Due to this, if Olya's fridge contains a carton past its expiry date, she throws it away.
Olya hates throwing out cartons, so when she drinks a carton, she chooses the one which expires the fastest. It's easy to understand that this strategy minimizes the amount of cartons thrown out and lets her avoid it if it's even possible.
<image> Milk. Best before: 20.02.2017.
The main issue Olya has is the one of buying new cartons. Currently, there are n cartons of milk in Olya's fridge, for each one an expiration date is known (how soon does it expire, measured in days). In the shop that Olya visited there are m cartons, and the expiration date is known for each of those cartons as well.
Find the maximum number of cartons Olya can buy so that she wouldn't have to throw away any cartons. Assume that Olya drank no cartons today.
Input
In the first line there are three integers n, m, k (1 ≤ n, m ≤ 106, 1 ≤ k ≤ n + m) — the amount of cartons in Olya's fridge, the amount of cartons in the shop and the number of cartons Olya drinks each day.
In the second line there are n integers f1, f2, ..., fn (0 ≤ fi ≤ 107) — expiration dates of the cartons in Olya's fridge. The expiration date is expressed by the number of days the drinking of this carton can be delayed. For example, a 0 expiration date means it must be drunk today, 1 — no later than tomorrow, etc.
In the third line there are m integers s1, s2, ..., sm (0 ≤ si ≤ 107) — expiration dates of the cartons in the shop in a similar format.
Output
If there's no way for Olya to drink the cartons she already has in her fridge, print -1.
Otherwise, in the first line print the maximum number x of cartons which Olya can buy so that she wouldn't have to throw a carton away. The next line should contain exactly x integers — the numbers of the cartons that should be bought (cartons are numbered in an order in which they are written in the input, starting with 1). Numbers should not repeat, but can be in arbitrary order. If there are multiple correct answers, print any of them.
Examples
Input
3 6 2
1 0 1
2 0 2 0 0 2
Output
3
1 2 3
Input
3 1 2
0 0 0
1
Output
-1
Input
2 1 2
0 1
0
Output
1
1
Note
In the first example k = 2 and Olya has three cartons with expiry dates 0, 1 and 1 (they expire today, tomorrow and tomorrow), and the shop has 3 cartons with expiry date 0 and 3 cartons with expiry date 2. Olya can buy three cartons, for example, one with the expiry date 0 and two with expiry date 2.
In the second example all three cartons Olya owns expire today and it means she would have to throw packets away regardless of whether she buys an extra one or not.
In the third example Olya would drink k = 2 cartons today (one she alreay has in her fridge and one from the shop) and the remaining one tomorrow.
Submitted Solution:
```
def p(a):
t = max(a)
x = True
for i in range(t + 1):
l = 0
for j in a:
if j <= i:
l += 1
if l > (i + 1) * k:
x = False
break
return x
n, m , k = map(int, input().split())
a = [int(i) for i in input().split()]
u = a.copy()
f = u.copy()
b = [int(i) for i in input().split()]
c = b.copy()
b.sort()
left = 0
right = m
if right == 1:
a.append(b[0])
if p(a) == False:
right = 0
else:
left = 1
while right - left >= 1:
ans = (left + right) // 2
a.extend(b[-ans:])
if p(a) == False:
right = ans - 1
else:
left = ans
a = u
if p(f) == True:
print(left)
for i in range(m - left, m):
print(c.index(b[i]) + 1, end=' ')
c[c.index(b[i])] = -1
else:
print(-1)
``` | instruction | 0 | 8,063 | 9 | 16,126 |
No | output | 1 | 8,063 | 9 | 16,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it exactly at the date written on the carton). Due to this, if Olya's fridge contains a carton past its expiry date, she throws it away.
Olya hates throwing out cartons, so when she drinks a carton, she chooses the one which expires the fastest. It's easy to understand that this strategy minimizes the amount of cartons thrown out and lets her avoid it if it's even possible.
<image> Milk. Best before: 20.02.2017.
The main issue Olya has is the one of buying new cartons. Currently, there are n cartons of milk in Olya's fridge, for each one an expiration date is known (how soon does it expire, measured in days). In the shop that Olya visited there are m cartons, and the expiration date is known for each of those cartons as well.
Find the maximum number of cartons Olya can buy so that she wouldn't have to throw away any cartons. Assume that Olya drank no cartons today.
Input
In the first line there are three integers n, m, k (1 ≤ n, m ≤ 106, 1 ≤ k ≤ n + m) — the amount of cartons in Olya's fridge, the amount of cartons in the shop and the number of cartons Olya drinks each day.
In the second line there are n integers f1, f2, ..., fn (0 ≤ fi ≤ 107) — expiration dates of the cartons in Olya's fridge. The expiration date is expressed by the number of days the drinking of this carton can be delayed. For example, a 0 expiration date means it must be drunk today, 1 — no later than tomorrow, etc.
In the third line there are m integers s1, s2, ..., sm (0 ≤ si ≤ 107) — expiration dates of the cartons in the shop in a similar format.
Output
If there's no way for Olya to drink the cartons she already has in her fridge, print -1.
Otherwise, in the first line print the maximum number x of cartons which Olya can buy so that she wouldn't have to throw a carton away. The next line should contain exactly x integers — the numbers of the cartons that should be bought (cartons are numbered in an order in which they are written in the input, starting with 1). Numbers should not repeat, but can be in arbitrary order. If there are multiple correct answers, print any of them.
Examples
Input
3 6 2
1 0 1
2 0 2 0 0 2
Output
3
1 2 3
Input
3 1 2
0 0 0
1
Output
-1
Input
2 1 2
0 1
0
Output
1
1
Note
In the first example k = 2 and Olya has three cartons with expiry dates 0, 1 and 1 (they expire today, tomorrow and tomorrow), and the shop has 3 cartons with expiry date 0 and 3 cartons with expiry date 2. Olya can buy three cartons, for example, one with the expiry date 0 and two with expiry date 2.
In the second example all three cartons Olya owns expire today and it means she would have to throw packets away regardless of whether she buys an extra one or not.
In the third example Olya would drink k = 2 cartons today (one she alreay has in her fridge and one from the shop) and the remaining one tomorrow.
Submitted Solution:
```
import sys
from collections import defaultdict
consume = 0
fridge = defaultdict(int)
shop = defaultdict(list)
cartons = []
for (index, line) in enumerate(sys.stdin):
if index == 0:
consume = int(line.split(' ')[2])
if index == 1:
if line.rstrip():
for x in line.split(' '):
fridge[int(x)] += 1
elif index == 2:
if line.rstrip():
for (index, day) in enumerate(line.split(' ')):
shop[int(day)].append(index + 1)
hold = 0
for day in range(max(fridge.keys()), -1, -1):
if fridge[day] < consume:
fridge[day] += hold
hold = 0
if fridge[day] > consume:
hold += fridge[day] - consume
fridge[day] = consume
if hold > 0:
print(-1)
sys.exit(0)
def more_cartons(day, num):
return sorted(shop[day])[0:num]
for (key, value) in fridge.items():
if value > consume:
print(-1)
sys.exit(0)
elif value < consume:
cartons += more_cartons(key, consume - value)
for (key, value) in shop.items():
if key not in fridge:
cartons += more_cartons(key, consume)
print(len(cartons))
print(' '.join([str(x) for x in sorted(cartons)]))
``` | instruction | 0 | 8,064 | 9 | 16,128 |
No | output | 1 | 8,064 | 9 | 16,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it exactly at the date written on the carton). Due to this, if Olya's fridge contains a carton past its expiry date, she throws it away.
Olya hates throwing out cartons, so when she drinks a carton, she chooses the one which expires the fastest. It's easy to understand that this strategy minimizes the amount of cartons thrown out and lets her avoid it if it's even possible.
<image> Milk. Best before: 20.02.2017.
The main issue Olya has is the one of buying new cartons. Currently, there are n cartons of milk in Olya's fridge, for each one an expiration date is known (how soon does it expire, measured in days). In the shop that Olya visited there are m cartons, and the expiration date is known for each of those cartons as well.
Find the maximum number of cartons Olya can buy so that she wouldn't have to throw away any cartons. Assume that Olya drank no cartons today.
Input
In the first line there are three integers n, m, k (1 ≤ n, m ≤ 106, 1 ≤ k ≤ n + m) — the amount of cartons in Olya's fridge, the amount of cartons in the shop and the number of cartons Olya drinks each day.
In the second line there are n integers f1, f2, ..., fn (0 ≤ fi ≤ 107) — expiration dates of the cartons in Olya's fridge. The expiration date is expressed by the number of days the drinking of this carton can be delayed. For example, a 0 expiration date means it must be drunk today, 1 — no later than tomorrow, etc.
In the third line there are m integers s1, s2, ..., sm (0 ≤ si ≤ 107) — expiration dates of the cartons in the shop in a similar format.
Output
If there's no way for Olya to drink the cartons she already has in her fridge, print -1.
Otherwise, in the first line print the maximum number x of cartons which Olya can buy so that she wouldn't have to throw a carton away. The next line should contain exactly x integers — the numbers of the cartons that should be bought (cartons are numbered in an order in which they are written in the input, starting with 1). Numbers should not repeat, but can be in arbitrary order. If there are multiple correct answers, print any of them.
Examples
Input
3 6 2
1 0 1
2 0 2 0 0 2
Output
3
1 2 3
Input
3 1 2
0 0 0
1
Output
-1
Input
2 1 2
0 1
0
Output
1
1
Note
In the first example k = 2 and Olya has three cartons with expiry dates 0, 1 and 1 (they expire today, tomorrow and tomorrow), and the shop has 3 cartons with expiry date 0 and 3 cartons with expiry date 2. Olya can buy three cartons, for example, one with the expiry date 0 and two with expiry date 2.
In the second example all three cartons Olya owns expire today and it means she would have to throw packets away regardless of whether she buys an extra one or not.
In the third example Olya would drink k = 2 cartons today (one she alreay has in her fridge and one from the shop) and the remaining one tomorrow.
Submitted Solution:
```
import sys
from collections import defaultdict
consume = 0
fridge = []
shop = []
cartons = []
for (index, line) in enumerate(sys.stdin):
if index == 0:
consume = int(line.split(' ')[2])
if index == 1:
fridge = defaultdict(int)
for x in line.split(' '):
fridge[int(x)] += 1
elif index == 2:
shop = defaultdict(list)
for (index, day) in enumerate(line.split(' ')):
shop[int(day)].append(index + 1)
def more_cartons(day, num):
return shop[day][0:num]
exit_flag = False
for (key, value) in fridge.items():
if value > consume:
exit_flag = True
break
elif value < consume:
cartons += more_cartons(key, consume - value)
if not exit_flag:
for (key, value) in shop.items():
if key not in fridge:
cartons += more_cartons(key, consume)
if exit_flag:
print(-1)
else:
print(len(cartons))
print(' '.join([str(x) for x in cartons]))
``` | instruction | 0 | 8,065 | 9 | 16,130 |
No | output | 1 | 8,065 | 9 | 16,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it exactly at the date written on the carton). Due to this, if Olya's fridge contains a carton past its expiry date, she throws it away.
Olya hates throwing out cartons, so when she drinks a carton, she chooses the one which expires the fastest. It's easy to understand that this strategy minimizes the amount of cartons thrown out and lets her avoid it if it's even possible.
<image> Milk. Best before: 20.02.2017.
The main issue Olya has is the one of buying new cartons. Currently, there are n cartons of milk in Olya's fridge, for each one an expiration date is known (how soon does it expire, measured in days). In the shop that Olya visited there are m cartons, and the expiration date is known for each of those cartons as well.
Find the maximum number of cartons Olya can buy so that she wouldn't have to throw away any cartons. Assume that Olya drank no cartons today.
Input
In the first line there are three integers n, m, k (1 ≤ n, m ≤ 106, 1 ≤ k ≤ n + m) — the amount of cartons in Olya's fridge, the amount of cartons in the shop and the number of cartons Olya drinks each day.
In the second line there are n integers f1, f2, ..., fn (0 ≤ fi ≤ 107) — expiration dates of the cartons in Olya's fridge. The expiration date is expressed by the number of days the drinking of this carton can be delayed. For example, a 0 expiration date means it must be drunk today, 1 — no later than tomorrow, etc.
In the third line there are m integers s1, s2, ..., sm (0 ≤ si ≤ 107) — expiration dates of the cartons in the shop in a similar format.
Output
If there's no way for Olya to drink the cartons she already has in her fridge, print -1.
Otherwise, in the first line print the maximum number x of cartons which Olya can buy so that she wouldn't have to throw a carton away. The next line should contain exactly x integers — the numbers of the cartons that should be bought (cartons are numbered in an order in which they are written in the input, starting with 1). Numbers should not repeat, but can be in arbitrary order. If there are multiple correct answers, print any of them.
Examples
Input
3 6 2
1 0 1
2 0 2 0 0 2
Output
3
1 2 3
Input
3 1 2
0 0 0
1
Output
-1
Input
2 1 2
0 1
0
Output
1
1
Note
In the first example k = 2 and Olya has three cartons with expiry dates 0, 1 and 1 (they expire today, tomorrow and tomorrow), and the shop has 3 cartons with expiry date 0 and 3 cartons with expiry date 2. Olya can buy three cartons, for example, one with the expiry date 0 and two with expiry date 2.
In the second example all three cartons Olya owns expire today and it means she would have to throw packets away regardless of whether she buys an extra one or not.
In the third example Olya would drink k = 2 cartons today (one she alreay has in her fridge and one from the shop) and the remaining one tomorrow.
Submitted Solution:
```
import sys
from collections import defaultdict
consume = 0
fridge = defaultdict(int)
shop = defaultdict(list)
cartons = []
for (index, line) in enumerate(sys.stdin):
if index == 0:
consume = int(line.split(' ')[2])
if index == 1:
if line.rstrip():
for x in line.split(' '):
fridge[int(x)] += 1
elif index == 2:
if line.rstrip():
for (index, day) in enumerate(line.split(' ')):
shop[int(day)].append(index + 1)
def more_cartons(day, num):
return sorted(shop[day])[0:num]
for (key, value) in fridge.items():
if value > consume:
print(-1)
sys.exit(0)
elif value < consume:
cartons += more_cartons(key, consume - value)
for (key, value) in shop.items():
if key not in fridge:
cartons += more_cartons(key, consume)
print(len(cartons))
print(' '.join([str(x) for x in sorted(cartons)]))
``` | instruction | 0 | 8,066 | 9 | 16,132 |
No | output | 1 | 8,066 | 9 | 16,133 |
Provide a correct Python 3 solution for this coding contest problem.
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i.
Tozan and Gezan repeats the following sequence of operations:
* If A and B are equal sequences, terminate the process.
* Otherwise, first Tozan chooses a positive element in A and decrease it by 1.
* Then, Gezan chooses a positive element in B and decrease it by 1.
* Then, give one candy to Takahashi, their pet.
Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.
Constraints
* 1 \leq N \leq 2 × 10^5
* 0 \leq A_i,B_i \leq 10^9(1\leq i\leq N)
* The sums of the elements in A and B are equal.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.
Examples
Input
2
1 2
3 2
Output
2
Input
3
8 3
0 1
4 8
Output
9
Input
1
1 1
Output
0 | instruction | 0 | 8,264 | 9 | 16,528 |
"Correct Solution:
```
N = int(input())
A = list()
B = list()
m = float('inf')
for i in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
if A == B: print(0)
else:
seriesSum = sum(A)
for i in range(N):
if A[i] > B[i]:
m = min(m, B[i])
print(seriesSum - m)
``` | output | 1 | 8,264 | 9 | 16,529 |
Provide a correct Python 3 solution for this coding contest problem.
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i.
Tozan and Gezan repeats the following sequence of operations:
* If A and B are equal sequences, terminate the process.
* Otherwise, first Tozan chooses a positive element in A and decrease it by 1.
* Then, Gezan chooses a positive element in B and decrease it by 1.
* Then, give one candy to Takahashi, their pet.
Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.
Constraints
* 1 \leq N \leq 2 × 10^5
* 0 \leq A_i,B_i \leq 10^9(1\leq i\leq N)
* The sums of the elements in A and B are equal.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.
Examples
Input
2
1 2
3 2
Output
2
Input
3
8 3
0 1
4 8
Output
9
Input
1
1 1
Output
0 | instruction | 0 | 8,265 | 9 | 16,530 |
"Correct Solution:
```
n = int(input())
INF = 10**9
csum = 0
min_b = INF
for _ in range(n):
a,b = map(int, input().split())
csum += a
if a > b:
min_b = min(min_b,b)
if min_b == INF:
print(0)
else:
ans = csum-min_b
print(ans)
# a_down_sum = 0
# top_diff = 0
# for _ in range(n):
# a,b = map(int, input().split())
# if a < b:
# a_down_sum += a
# else:
# top_diff = max(top_diff,a-b)
``` | output | 1 | 8,265 | 9 | 16,531 |
Provide a correct Python 3 solution for this coding contest problem.
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i.
Tozan and Gezan repeats the following sequence of operations:
* If A and B are equal sequences, terminate the process.
* Otherwise, first Tozan chooses a positive element in A and decrease it by 1.
* Then, Gezan chooses a positive element in B and decrease it by 1.
* Then, give one candy to Takahashi, their pet.
Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.
Constraints
* 1 \leq N \leq 2 × 10^5
* 0 \leq A_i,B_i \leq 10^9(1\leq i\leq N)
* The sums of the elements in A and B are equal.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_N B_N
Output
Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.
Examples
Input
2
1 2
3 2
Output
2
Input
3
8 3
0 1
4 8
Output
9
Input
1
1 1
Output
0 | instruction | 0 | 8,266 | 9 | 16,532 |
"Correct Solution:
```
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
s = 0
m = float('inf')
for i, (A, B) in enumerate(AB) :
s += A
if A > B :
m = min(m, B)
if m == float('inf') :
print(0)
else :
print(s - m)
``` | output | 1 | 8,266 | 9 | 16,533 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.