Problem:


	MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

カレー作り

ACM-ICPC国内予選が近づいてきたので，練習に追い込みをかけたいと思っていたあなたは，友人宅で行われる競技プログラミング合宿に参加することにした．
参加者のこだわりで，食事は自炊することになった．

合宿初日の夜，参加者達はその日の練習を終え，夕食の準備に取り掛かり始めた．
競技プログラミングだけでなく，自炊でも「プロ」と友人によく言われるあなたは，担当分のメニューをあっという間に作り終えてしまい，暇を持て余してしまった．
そこで，他の人が担当していたカレー作りを手伝うことにした．

今，W0 [L] の水に R0 [g] のルウを混ぜた作りかけのカレーがある．
今回使うルウは 1 種類で，1 個あたり R [g] である．ルウは十分な量の備蓄がある．
あなたはこのルウを使う場合，濃度が C [g/L] のカレーが最も美味しいと考えているので，このカレーにいくつかのルウと水を適切に加え，濃度を C [g/L] にしたいと考えている．
ここで，ルウ R0 [g] が水 W0 [L] に溶けているカレーの濃度は R0 / W0 [g/L] であり，このカレーに R [g] のルウを X 個と水 Y [L] を追加すると，その濃度は (R0 + X R) / (W0 + Y) [g/L] になる．
ルウは大量にあるものの，使い過ぎるのは良くないと考えたあなたは，追加するルウの個数を出来る限り少なくして濃度 C [g/L] のカレーを作ることにした．

濃度 R0/W0 [g/L] のカレーに，ルウか水のいずれか，またはその両方を適切に加えることによって濃度 C [g/L] のカレーを作るとき，追加すべきルウの個数 X の最小値を求めて欲しい．

ただし，今回のカレー作りについては，以下の事柄に注意すること．

追加するルウの個数 X の値は 0 以上の整数でなければならない．つまり，ルウを 1/3 個分だけ追加する，といったことは出来ない．

追加する水の体積 Y の値は 0 以上の実数として良く，整数である必要はない．

ルウか水のいずれか，またはその両方を追加しなくても濃度 C のカレーを作ることが出来る場合もある．

ルウや水は十分な量を確保しているので，ルウや水が足りず濃度 C のカレーを作ることが出来ない，という事態は起こらないとして良い．

Input

入力は複数のデータセットからなる．
各データセットは 1 行からなり，次の形式で表される．

R0 W0 C R

ここで，R0，W0，C，R はそれぞれ作りかけのカレーに既に溶け込んだルウの質量 [g]，カレーに含まれる水の体積 [L]，あなたが作りたいカレーの濃度 [g/L]，ルウ 1 個あたりの質量 [g] を表す．
これらの値は，全て 1 以上 100 以下の整数である．
入力の終わりは，空白で区切られた 4 つのゼロからなる行によって示される．

Output

各データセットについて，W0 [L] の水に R0 [g] のルウを混ぜた作りかけのカレーから，濃度 C のカレーを作るために追加する必要のあるルウの個数の最小値を 1 行で出力すること．追加する水の量を出力してはならない．

入力制約から，各データセットの答えとなるルウの個数の最小値は，32ビット符号付き整数で表現される範囲におさまることが保証されることに注意せよ．

Sample Input

10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0

Output for Sample Input

2
3
0
0
9
96



Sample input:
10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0


Sample output:
2
3
0
0
9
96

Submission status: Wrong Answer

Solution code:
while 1:
    r,w,c,a = map(int,raw_input().split())
    if r == w == c == a == 0:
        break
    b = 0
    sum = 0
    if r % c == 0:
        if r / c >= w:
            b = 1
    while b == 0:
        sum += 1
        r += a
        if r/c>=w:
            b = 1
    print sum

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
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():
    rr = []

    while True:
        a,b,c,d = LI()
        if a == 0:
            break
        for r in range(1000):
            if (a+d*r) / b >= c:
                rr.append(r)
                break

    return '\n'.join(map(str, rr))


print(main())

Submission status: Wrong Answer

Solution code:
l_raw = input().split()
l = [int(n) for n in l_raw]

try:
    l[0]/l[1]
except:
    exit()

if l[2] <= l[0]/l[1]:
    print(0)
else:
    print(-(-(l[2]*l[1]-l[0])//l[3]))

Submission status: Accepted

Solution code:
while True:
    R0, W0, C, R = map(int, input().split())
    if R0 == 0 and W0 == 0 and C == 0 and R == 0:
        break
    i = 0
    while True:
        if (R0 + i * R) // W0 >= C:
            print(i)
            break
        i += 1

Submission status: Accepted

Solution code:
while True:
    r0,w0,c,r=map(int,raw_input().split())
    if r0==0: break
    i=0
    while True:
        if r0+i*r>=c*w0:
            print i
            break
        i+=1

Submission status: Accepted

Solution code:
import math
while True:
    r,w,c,vr = map(int,input().split())
    if r==w==0: break
    r = math.ceil((w*c-r)/vr) if w*c-r>=0 else 0
    print(r)

Submission status: Accepted

Solution code:
while True:
    r_0,w_0,c,r = map(int,input().split())
    if r_0 == w_0 == c == r:
        break
    if c <= (r_0/w_0):
        print(0)
    else:
        num = 0
        while True:
            num += 1
            r_0 += r
            if c <= (r_0/w_0):
                print(num)
                break

Submission status: Accepted

Solution code:
import math
while 1:
    r,w,c,rr=map(int,input().split())
    if r==w==c==rr==0:break
    print(math.ceil((w*c-r)/rr) if w*c-r>=0 else 0)

Submission status: Accepted

Solution code:

while True:
  R0, W0, C, R = map(int, input().split())
  if R0 + W0 + C + R == 0:
    break
  n = 0
  while True:
    if (n * R + R0) / W0 >= C:
      break
    n += 1
  print(n)

Submission status: Accepted

Solution code:
while True:
    R0, W0, C, R = map(int, input().split())
    if R0 == W0 == C == R == 0:
        break
    X = 0
    while True:
        tmp = R0 + X * R - C * W0
        if tmp >= 0:
            print(X)
            break
        else:
            X += 1

Submission status: Accepted

Solution code:
while True:
    R0, W0, C, R = map(int, input().split())
    if R0 == W0 == C == R == 0:
        break
    X = 0
    while True:
        if R0 + X * R - C * W0 >= 0:
            print(X)
            break
        else:
            X += 1

Submission status: Accepted

Solution code:
while 1:
    r0, w0, c, r = map(int, input().split())
    if r0+w0+c+r < 1:
        break
    print(max((c*w0-r0+r-1)//r, 0))

Submission status: Accepted

Solution code:
while 1:
    r,w,c,a = map(int,raw_input().split())
    if r == w == c == a == 0:
        break
    b = 0
    sum = 0
    if r / c >= w:
            b = 1
    while b == 0:
        sum += 1
        r += a
        if r/c>=w:
            b = 1
    print sum

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    while 1:
        r0,w0,c,r = list(map(int,input().strip().split()))
        if r0 ==w0 ==c ==r ==0:break
        for x in  range(10000):
            y = r0 + r*x - c*w0
            if y >=0 :break
        print(x)

Submission status: Accepted

Solution code:
while True:
    R0,W0,C,R = map(int,input().split())
    if R0 == 0: break
    x = 0
    while True:
        r = R0 + x*R
        if r >= W0 * C:
            break
        x += 1
    print(x)

Submission status: Accepted

Solution code:
while True:
    R_0, W_0, C, R = map(int, raw_input().split())

    if R_0 == 0 and W_0 == 0 and C == 0 and R == 0:
        break

    t = C * W_0 - R_0
    print max(0, t / R if t % R == 0 else t / R + 1)

Submission status: Accepted

Solution code:
while True:
    R_0, W_0, C, R = map(int, raw_input().split())

    if R_0 == 0 and W_0 == 0 and C == 0 and R == 0:
        break

    t = max(0, C * W_0 - R_0)
    print t / R if t % R == 0 else t / R + 1

Submission status: Accepted

Solution code:
while True:
    r0, w0, c, r = map(int, input().split())
    if r0 == 0:
        break
    print(max(0, (w0 * c - r0 - 1) // r + 1))

Submission status: Accepted

Solution code:
while True:
    r0, w0, c, r = map(int, input().split())
    if r0 == 0:break
    print(0 if w0 * c <= r0 else -((r0 - w0 * c) // r))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
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():
    rr = []

    while True:
        a,b,c,d = LI()
        if a == 0:
            break
        for r in range(10000):
            if 1.0 * (a+d*r) / b >= c:
                rr.append(r)
                break

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
l_raw = input().split()
l = [int(n) for n in l_raw]

while l!=[0,0,0,0]:
    if l[2] <= l[0]/l[1]:
        print(0)
    else:
        print(-(-(l[2]*l[1]-l[0])//l[3]))
    l_raw = input().split()
    l = [int(n) for n in l_raw]

Submission status: Accepted

Solution code:
while 1:
  R0,W0,C,R=map(int,input().split())
  if not R0 and not W0 and not C and not R:break
  n=0
  while 1:
    if W0>1 and int((R0+R*n)/W0)>=C:break
    elif W0==1 and (R0+R*n)>=C:break 
    n+=1
  print(n)

Submission status: Accepted

Solution code:
import math
while 1:
    r0,w0,c,r = map(int,input().split())
    if r0 == 0 and w0 == 0 and c == 0 and r == 0:
        break
    for i in range(100000):
        if c <= (r0+i*r) // w0:
            print(i)
            break

Submission status: Accepted

Solution code:
def get_four_int():
    four_int = input().split()
    for i, v in enumerate(four_int):
        four_int[i] = int(v)
    return four_int

def get_min_roux_num(initial_roux, initial_water, ideal_concentration, min_unit):
    roux = initial_roux
    min_roux_num = 0
    min_required_roux = initial_water * ideal_concentration
    while True:
        if roux >= min_required_roux:
            return min_roux_num
        roux += min_unit
        min_roux_num += 1


if __name__ == "__main__":
    while True:
        initial_roux, initial_water, ideal_concentration, min_unit = get_four_int()
        if initial_roux == 0:
            break
        min_roux_num = get_min_roux_num(initial_roux, initial_water, ideal_concentration, min_unit)
        print(min_roux_num)

Submission status: Accepted

Solution code:

Q=[]
while True:
    A=list(map(int,input().split()))
    if A==[0,0,0,0]:
        break
    else:
        Q.append(A)

for k in range(len(Q)):
    for i in range(100000):
        P=(Q[k][0]+i*Q[k][3])/Q[k][2]-Q[k][1]
        if P>=0:
            print(i)
            break

Submission status: Accepted

Solution code:
R0, W0, C, R = list(map(int, input().split()))
f=0
if R0 == W0 == C == R == 0:
    f+=1
while f==0:
    for X in range(10**5):
        if ((R0-W0*C)+R*X)>=0:
            y = ((R0-W0*C)+R*X)/C
            print(X)
            break
        else:
            continue
    R0, W0, C, R = list(map(int, input().split()))
    if R0 == W0 == C == R == 0:
        f+=1

Submission status: Accepted

Solution code:
while (True):
  r_count = 0
  r0, w0, c, r = map(int, input().split())
  if not(r0 and w0 and c and r):
    break
  
  while ((r0 + r * r_count) / w0 < c):
    r_count += 1

  print(r_count)

Submission status: Accepted

Solution code:
import math
while True:
	r0,w,c,r=map(int,input().split())
	if [r0,w,c,r]==[0,0,0,0]:
		exit()
	ans=math.ceil((c*w-r0)/r)
	print(max(ans,0))

Submission status: Accepted

Solution code:
while True:
    R0, W0, C, R = map(int, input().split(' '))
    if R0 == 0 and W0 == 0 and C == 0 and R == 0:
        break
    cnt = 0
    while R0/W0 < C:
        R0 += R
        cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:

def updiv(a,b):
    if a % b == 0:
        return a // b
    else:
        return a // b + 1
    
while True:

    r,w,C,R = map(int,input().split())

    if r == 0 and w == 0 and C == 0 and R == 0:
        break

    if r/w >= C:
        print (0)
    else:
        print (updiv(w*C-r,R))

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

ans = []

def solve(R0, W0, C, R):
    if C*W0 <= R0 :
        return 0
    else :
        return (W0 * C - R0 - 1) // R + 1


while True :
    R0, W0, C, R = LI()
    if R0 == 0:
        break
    ans.append(solve(R0, W0, C, R))

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
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(): return list(sys.stdin.readline())[:-1]
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(r0,w,c,r):
    c0 = r0/w
    if c0 >= c:
        print(0)
        return
    x = math.ceil((w*c-r0)/r)
    print(x)
    return

#Solve
if __name__ == "__main__":
    while 1:
        r0,w,c,r = LI()
        if r0 == w == c == r == 0:
            break
        solve(r0,w,c,r)

Submission status: Accepted

Solution code:
while True:
        R0,W0,C,R = map(int,input().split())
        if R0 + W0 + C + R == 0: break
        ans = 0
        while True:
                if (R0 + R * ans) / C >= W0:
                        print(ans)
                        break
                ans += 1

Submission status: Accepted

Solution code:
import math

def main():
    while True:
        r0,w0,c,r = map(int,input().split())
        if not r0 and not w0 and not c and not r:
            return
        current = r0/w0
        ans = 0
        if c < current:
            ans = 0
        else:
            ans = math.ceil((c*w0-r0)/r)
        
        print(ans)
            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def Con(X) :
	# concentration 濃度
	if(r + X * R - C * w  >= 0) :
		return 0
	else :
		return 1

	
while True :
	r, w, C, R = map(int, input().split())
	if(C == 0) :
		break
	else :
		for i in range(10000) :
			if(Con(i) == 0) :
				print(i)
				break
			else :
				pass

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
while True:
    r0, w0, c, r = map(int, input().split())
    if r0 == 0:
        break
    for x in range(10001):
        if r0 + x * r >= c * w0:
            print(x)
            break

Submission status: Accepted

Solution code:
import math

while True:
    Rzero, W, C, R = map(int, input().split())
    # 最初のルウRzero, 最初の水, 濃度Cのルウがベスト, 一個のルウが
    if Rzero == 0:
        break
    aim_status = W * C
    ans = math.ceil((aim_status-Rzero)/R)
    if ans < 0:
        ans = 0
    print(ans)

Submission status: Accepted

Solution code:
while True:
  r,w,c,x=map(int,input().split())
  if w==c==x==0:
    break
  a=0
  while True:
    if (a*x+r)/w>=c:
      break
    a+=1
  print(a)

Submission status: Accepted

Solution code:
r,w,c,rr=map(int,input().split())
lsr=[]
lsw=[]
lsc=[]
lsrr=[]
n=0
m=0
while True:
    R,W,C,RR=map(int,input().split())
    lsr.append(R)
    lsw.append(W)
    lsc.append(C)
    lsrr.append(RR)
    if R==0:
        break
    n+=1

if lsr[0]/lsw[0]>=lsc[0]:
        print(0)
else:
    while lsr[0]+lsrr[0]*m<lsw[0]*lsc[0]:
        m+=1
    print(m-1)
for i in range(n):
    m=0
    
    if lsr[i]/lsw[i]>=lsc[i]:
        print(0)
    else:
        while lsr[i]+lsrr[i]*m<lsw[i]*lsc[i]:
            m+=1
        print(m)

Submission status: Accepted

Solution code:
import math
while 1:
    r0,w0,c,r=map(int,input().split())
    if r0==w0==c==r==0:break
    r1=w0*c
    if r1<=r0:print("0")
    else:
        nw=r1-r0
        print(math.ceil(nw/r))

Submission status: Accepted

Solution code:
while 1:
    r0, w0, c, r = map(int, input().split())
    if r == 0:
        break

    tmp = w0 * c - r0
    if tmp % r == 0:
        print(max(tmp // r, 0))
    else:
        print(max(tmp // r + 1, 0))

Submission status: Accepted

Solution code:
while True:
    R0, W0, C, R = map(int, input().split())
    if R0 + W0 + C + R == 0:
        break
    print(max((C * W0 - R0 + R -1) // R, 0))

Submission status: Accepted

Solution code:
import math
while True:
    r0, w0, c, r = map(int, input().split())
    if (r0+w0+c+r) == 0:
        break
    else:
        tmp = math.ceil((w0*c - r0) / r)
        if tmp < 0:
            print(0)
        else:
            print(tmp)

Submission status: Accepted

Solution code:
# coding: utf-8
while 1:
    r0,w0,c,r=map(int,input().split())
    if r0==0:
        break
    n=r0/w0
    x=0
    if n>=c:
        print(0)
        continue
    while n<c:
        x+=1
        n=(r0+r*x)/w0
    print(x)

Submission status: Runtime Error

Solution code:
while 1:
    r,w,c,a = map(int,raw_input().split())
    if r == w == c == a == 0:
        break
    b = 0
    sum = 0
    if r % c == 0:
        if r / c >= w:
            b = 1
    while b == 0:
        sum += 1
        r += a
        if r % c == 0:
            if r/c>=w:
                b = 1
    print sum

Submission status: Runtime Error

Solution code:
while 1:
  R0,W0,C,R=map(int,input().split())
  if not R0 and not W0 and not C and not R:break
  n=0
  while 1:
    if W0>1 and int((R0+R*n)/W0)==C:break
    elif W0==1 and (R0+R*n)>=C:break 
    n+=1
  print(n)