Problem:


Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000



Sample input:
2 1 1 3


Sample output:
2

Submission status: Accepted

Solution code:
n_plus, n_zero, n_minus, n_cards = map(int, input().split())

if n_cards <= n_plus:
  print(min(n_plus, n_cards))
elif n_cards <= (n_plus + n_zero):
  print(n_plus)
else:
  print(n_plus - (n_cards - n_plus - n_zero))

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

a,b,c,k=MI()
ans=0

if k-a>=0:
    ans+=a
    k-=a
else:
    print(k)
    exit()

if k-b>=0:
    k-=b
else:
    print(ans)
    exit()

print(ans-k)

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())

if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(A-K+A+B)

Submission status: Accepted

Solution code:
a, b, c , k = map(int, input().split())

if k <= a:
    print(k)
elif k<=a+b:
    print(a)
else:
    print(2*a+b-k)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

NC = K - (A + B)

if NC >= 0:
    print(f"{A - NC}")
else:
    print(f"{min(A, K)}")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
A, B, C, K = list(map(int, input().split()))

# 求解処理
result = int()
if K <= A:
    result = K
elif A < K and K <= A + B:
    result = A
elif A + B < K and K <= A + B + C:
    result = 2*A + B - K

# 結果出力
print(result)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

ans=0

if a >= k:
    ans += k

else:
    ans += a
    k = k-a
    if b < k:
        k = k-b
        ans -= k

print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=map(int, input().split())

sum = 0
end = False
if a < k:
    sum+=a
    k-=a
else:
    sum=k
    end=True

if end==False and b < k:
    k-=b
else:
    end=True

if end==False:
    sum-=k

print(sum)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

ans = 0
if a < k:
    ans += a
    k -= a
elif k <= a:
    print(k)
    exit()

if b < k:
    k -= b
elif k <= b:
    print(ans)
    exit()

ans += -1*k
print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

if k > a:
    if k > a+b:
        print(a - (k - a - b))
    else:
        print(a)
else:
    print(k)

Submission status: Accepted

Solution code:
a,b ,c, k=list(map(int, input().split()))
ans=0
ans+=min(k, a)
ans+=-min(max(k-a-b,0), c)
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

ans = 0
if K > A:
    ans += 1 * A
    K -= A
else:
    ans += 1 * K
    print(ans)
    exit()

if K > B:
    ans += 0 * B
    K -= B
else:
    ans += 0 * K
    print(ans)
    exit()

if K > C:
    ans += -1 * C
    K -= C
else:
    ans += -1 * K
    print(ans)
    exit()

print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

if A >= K:
    print(K)
elif A+B >= K:
    print(A)
else:
    r = K - (A+B)
    print(A - r)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a, b, c, k = map(int, input().split())

result = 0

if 0 < k <= a:
    result += k
    k = 0
else:
    result += a
    k -= a

if 0 < k <= b:
    k = 0
elif b < k:
    k -= b

result -= k
k = 0

print(result)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

a,b,c,k = MI()

if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(a - (k-a-b))

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())

if a >= k:
    r = k
elif a+b >= k:
    r = a
elif a+b+c >= k:
    r = a - (k-a-b)

print(r)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
ans = 0
if k<=a:
    print(k)
elif a<k and k<=a+b:
    print(a)
else:
    print(a-min(k-a-b,c))

Submission status: Accepted

Solution code:
A,B,C,K = map(int, input().split())

if A >= K:
  print(K)
elif A + B >= K > A:
  print(A)
else:
  print(A - (K - A - B))

Submission status: Accepted

Solution code:
A, B, C, K= map(int, input().split())

ans = 0
if A >= K:
  ans = K
  print(K)
  exit()
else:
  ans = A
if B >= K-A:
  print(ans)
  exit()
else:
  ans = A

ans -= K-(A+B)
print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
s = 0
for i in [[a, 1], [b, 0], [c, -1]]:
    if k <= 0:
        break
    v = (i[0] if i[0] <= k else k)
    s += i[1] * v
    k -= v
print(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

(A, B, C, K) = (int(i) for i in input().split())

ans = 0
left = K

# 1
ans = min(A, left)

left -= A

if left <= 0:
    print(ans)
    sys.exit()

# 0
left -= B

if left <= 0:
    print(ans)
    sys.exit()

# -1
ans -= min(C, left)

print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = list(map(int, input().split()))

if k <= a+b:
    ans = min(a,k)
else:
    ans = 2*a+b-k
print(ans)

Submission status: Accepted

Solution code:





data = input().split()

a,b,c,k = int(data[0]),int(data[1]),int(data[2]),int(data[3])



res = min(a,k)
if (k > a + b):
    res -= k - (a + b)
print(res)

Submission status: Accepted

Solution code:
a, b, c, k = input().split()
count = 0
if int(a) <= int(k):
  count += int(a)
  if int(k)-int(a) >= int(b):
    count -= int(k)-int(a)-int(b)
else:
  count = int(k)
print(count)

Submission status: Accepted

Solution code:
a, b, c, k = map(int,input().split())
sum = 0
if a >= k:
    print(k)
    exit()
else:
    sum += a
    k -= a

if b >= k:
    print(sum)
    exit()
else:
    k -= b

print(sum - k)

Submission status: Accepted

Solution code:
from math import *
from collections import *
from itertools import *
from bisect import *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')
MOD = 1000000007
MAX=2147483647
MIN=-2147483648
p=input
# for _ in range(int(p())):
a,b,c,d=io()
s=0
s+=min(a,d)
d-=min(d,a)
d-=min(d,b)
s-=min(d,c)
print(s)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())

if A>=K:
    print(K)
elif A<K<=A+B:
    print(A)
elif A+B<K:
    print(2*A+B-K)

Submission status: Accepted

Solution code:
A, B, C, K = list(map(int, input().split()))

if K <= A:
    ans = K
elif K <= A + B:
    ans = A
else:
    ans = A - (K - A - B)

print(ans)

Submission status: Accepted

Solution code:
l = list(map(int,input().split()))
if l[0] >= l[3]:
    print(l[3])
else:
    if l[0] + l[1] >= l[3]:
        print(l[0])
    else:
        print(l[0]-(l[3]-l[0]-l[1]))

Submission status: Accepted

Solution code:
a,b,c,k=map(int, input().split())
max=0
if a>=k:
  max+=1*k
  print(max)
elif a<k:
  max+=a*1
  if b<k-a:
    max-=(k-a-b)
    print(max)
  else:
    print(max)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
k = K
if k <= A:
  a = k
else:
  a = A
k = k - a
if k <= B:
  b = k
else:
  b = B
k = k - b
c = k
print(a-c)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
if A>=K:
  print(K)
elif A<K<=A+B:
  print(A)
else:
  print(A-K+A+B)

Submission status: Accepted

Solution code:
a, b, c, k = map(int,input().split())

if a >= k:
    print(k)
elif b >= k-a:
    print(a)
else:
    print(a - (k - a - b))

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())

if a+b>=k:
  print(min(a,k))
else:
  c=k-(a+b)
  print(a-c)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

n = 0

if K >= A:
    n += A
    K -= A
    if K >= B:
        n -= (K-B)

else:
    n = K

print(n)

Submission status: Accepted

Solution code:
def main(A, B, C, K):
    if K - A <= 0:
        print(K)
    elif K - A > 0 and K - A - B <= 0:
        print(A)
    else:
        print(A - (K - A - B))

if __name__ == '__main__':
    A, B, C, K = list(map(int, input().split()))
    main(A, B, C, K)

Submission status: Accepted

Solution code:
def resolve():
    a,b,c,k = map(int, input().split())
    ans=0
    if k<a:
        ans+=k
        print(ans)
    else:
        k-=a
        ans+=a
        if k<b:
            print(ans)
        else:
            k-=b
            ans-=k
            print(ans)
resolve()

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

if K <= A:
    print(K)
elif A <= K <= A + B:
    print(A)
else:
    print(A - (K - (A + B)))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
if k <= a:
    print(k)
elif a < k <= a + b:
    print(a)
elif a + b < k <= a + b + c:
    print(a - (k - a - b))
else:
    print(a - c)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
    exit()
if K - A <= B:
    print(A)
    exit()
if A + B + C <= K:
    print(A - C)
else:
    print(A - (K-(A+B)))

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

point = 0

for card, card_point in [(A, 1), (B, 0), (C, -1)]:
    if K == 0:
        break
    if K >= card:
        point += card_point * card
        K -= card
    else:
        point += card_point * K
        K = 0


print(point)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

a = K - A
b = a - B
c = 0
if b > 0:
    c = K - b

if a < 0:
    print(K)
elif b > 0:
    print(A - b)
else:
    print(A)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())
ans=0
a=min(K,A)
K-=a
b=min(K,B)
K-=b
c=K
print(a-c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

a, b, c, k = map(int, input().split())
ans = 0

if a <= k:
    ans += a
    k -= a
else:
    print(k)
    exit()

if b <= k:
    k -= b
else:
    print(ans)
    exit()

print(ans - k)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
point = 0

if K >= A:
  K -= A
  point += A
  
  if K >= B:
    K -= B
    point -= K
    

else:
  point += K
  
print(point)

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
ans = 0

ans += min(A,K)
K -= ans
K -= B
if K > 0:
  ans -= min(K,C)
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())
ans = 0
k = K
ans += k if A >= k else A
k -= A + B
ans -= k if k > 0 else 0
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())

if k<=a:
    print(k)
elif k<=a+b:
    print(a)
else:
    print(a-(k-(a+b)))

Submission status: Accepted

Solution code:
import sys

a,b,c,k=map(int,input().split())

cnt=0


if k<=a:
  print(k)
  sys.exit()

if k<=(a+b):
  print(a)
  sys.exit()


k-=(a+b)
print(a-k)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
ans=0
if a>=k:
	print(k)
else:
	ans+=a
	if k-a<=b:
		print(ans)
	else:
		ans-=k-a-b
		print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

ans = 0

nokori = K

if A >= K:
    print(K)
    exit()

else:
    ans += A
    nokori = K - A

    if B >= nokori:
        print(ans)
        exit()
    
    else:
        nokori = nokori - B
        ans = ans - nokori
        print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())

if a >= k:
  z = k
elif a+b >= k:
  z = a
else:
  z = a-(k-a-b)
print(z)

Submission status: Accepted

Solution code:
def ABC_167_B():
    A,B,C,K = map(int, input().split())

    if A>=K:
        print(K)
    elif A+B >= K:
        print(A)
    else:
        print(A-(K-A-B))


if __name__ == '__main__':

    ABC_167_B()

Submission status: Accepted

Solution code:
ABCK = input().split()
A = int(ABCK[0])
B = int(ABCK[1])
C = int(ABCK[2])
K = int(ABCK[3])
ans = 0

if A >= K:
    ans = K
elif A + B >= K:
    ans = A
else:
    ans = 2*A + B - K

print(ans)

Submission status: Accepted

Solution code:
A,B,C,K = (int(x) for x in input().split())

if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(A-(K-A-B))

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())
l = max(0, k - a)
m = max(0, l - b)
print(min(k, a) - m)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

result = 0

if K <= A:
    result = K
else:
    result = A
    K = K - A
    if K <= B:
        pass
    else:
        result -= K - B

print(result)

Submission status: Accepted

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    a,b,c,k=MI()
    ans =0
    if k>=a:
        ans+=a
        k-=a
    elif k<a:
        ans+=k
        k=0
    if k>=b:
        ans+=0
        k-=b
    elif k<b:
        ans+=0
        k=0
    # print(ans,k)
    if k>=c:
        ans-=c
        k-=c
    elif k<c:
        ans-=k
        k=0
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
ANS = 0

ANS += min([A,K])
K -= A
K -= B

if K<1:
    print(ANS)
    exit()
ANS -= min([C,K])
print(ANS)

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = [int(x) for x in input().split()]
    ans = 0
    # 1
    if a >= k:
        ans += k
        k -= k
    else:
        ans += a
        k -= a
    # 0
    if b >= k:
        k -= k
    else:
        k -= b
    # -1
    ans -= k
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
def main():
    A, B, C, K = list(map(int, input().split()))

    rest = K
    total = 0

    if(rest - A >= 0):
        rest = max(0, rest - A) 
        total += 1 * A
    else:
        total += 1 * rest

    rest = max(0, rest - B) 

    
    total += -1 * rest

    print(total)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!python3

def LI():
    return list(map(int, input().split()))

# input
A, B, C, K = LI()


def main():
    a = min(A, K)
    k = K - a
    b = min(B, k)
    k -= b
    c = min(C, k)
    ans = a - c
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def linear(a, b, c, k):
  count = 0
  if(k>a):
    count+=a
    k-=a
    if(k>b):
      k-=b
      if(k>c):
        count-=c
      else:
        count-=k
    return count
  else:
    return k

a, b, c, k = map(int, input().split())
print(linear(a, b, c, k))

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())


if A > K:
    print(K)
elif A + B > K:
    print(A)
else:
    print(A - (K - A - B))

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())

if k<=a:
    print(k)
elif k<=a+b:
    print(a)
elif k<=a+b+c:
    print(a-(k-a-b))

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
ans=0
if a>=k:
    ans=k
    print(ans)
elif a<k<=a+b:
    ans=a
    print(ans)
elif a+b<k<=a+b+c:
    ans=a+(-1)*(k-(a+b))
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
A, B, C, K = map(int, input().split())
ans = 0

if K<=A:
    ans = K
else:
    if K-A <= B:
        ans = A
    else:
        ans = A - (K - A - B)
print(ans)

Submission status: Accepted

Solution code:
A, B, C, D = map(int, input().split())
ans = min(A, D)
D -= ans
if D > 0:
    D -= min(B, D)
if D > 0:
    ans -= min(C, D)
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

if K <= A:
    print(K)
elif K <= A + B:
    print(A)
elif K <= A + B + C:
    print(A-(K-A-B))

Submission status: Accepted

Solution code:
a,b,c,k = map(int, input().split(" "))

if k <= a:
  print(k)
elif k > a and k <= a+b:
  print(a)
else:
  print(a*2+b-k)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    sum = 0

    if a[0] >= a[3] :
        sum = a[3]
        a[3] = 0
    else:
        sum = a[0]
        a[3] =a[3]-a[0]
    if a[3] > 0:
        a[3] = a[3]-a[1]
    if a[3] >0:

        sum =sum -a[3]


    print(sum)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

if K<A:
    result = 1*K
elif A<=K and K<=A+B:
    result = 1*A
elif A+B<K and K<=A+B+C:
    result = 1*A + (-1)*(K-A-B)
else:
    result = 1*A + (-1)*C

print(result)

Submission status: Accepted

Solution code:
data = list(map(int,input().split()))

if(data[0] >= data[3]):
    print(data[3])
elif(data[0]+data[1] >= data[3]):
    print(data[0])
else:
    print(2*data[0]-data[3]+data[1])

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
elif (a < k) & (k <= a + b):
    print(a)
else:
    print(a-1*(k-a-b))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())

if a>k:
    ans = k
elif a+b>k:
    ans = a
else:
    ans = a-(k-a-b)

print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
ans = 0
if k - a >= 0:
    ans = a
else:
    ans = k
k -= a
k -= b
if k > 0:
    if k - c >= 0:
        ans -= c
    else:
        ans -= k
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=map(int, input().split())
ans=0
if a>=k:
  ans=k
elif a+b>=k:
    ans=a
else:
  ans=a-(k-a-b)
print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

s = 0

if k <= a :
    s = 1 * k
else :
    if k <= (a+b):
        s = 1 * a
    else :
        s = 1 * a + (-1) * (k-a-b)

print(s)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
if a<k:
    if b<k-a:
        ans=a+(k-a-b)*(-1)
    else:
        ans=a
else:
    ans=k
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input('').split(' '))
d=0
if k<=a:
    d=d+k
elif k<=a+b:
    d=d+a
elif k<=a+b+c:
    d=d+a-(k-(a+b))
else:
    d=a-c

print(d)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

ans = 0

if K - A >= 0:
    ans += A
    K -= A
else:
    ans += K
    print(ans)
    exit()

K -= B

if K > 0:
    if K-C >= 0:
        ans -= C
    else:
        ans -= K

print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
ans=0
if k>=a:
    k-=a
    ans+=a
else:
    ans+=k
    k=0
if k>=b:
    k-=b
else:
    k=0
if k>=c:
    ans-=c
    k-=c
else:
    ans-=k
    k=0
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
if k<=a:
    print(k)
else:
    #k>a
    k-=a
    ans=a
    if k<=b:
        print(ans)
    else:
        k-=b
        print(ans+-1*k)

Submission status: Accepted

Solution code:
A,B,C,K=input().split()
if int(A)>=int(K):
  print(int(K))
elif (int(A)+int(B))>=int(K):
  print(int(A))
else:
  print(2*int(A)+int(B)-int(K))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())

if k<a:
  print(k)
elif a<=k and k<=a+b:
  print(a)
elif a+b<k and k<a+b+c:
  print(a-(k-a-b))
else:
  print(a-c)

Submission status: Accepted

Solution code:
A,B,C,K=map(int,input().split())

if A>=K:
  print(K)
elif A<K and K<=A+B:
  print(A)
else:
  print(A-(K-A-B))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    a, b, c, k = map(int, input().split())
    if a >= k:
        ans = k
    else:
        ans = a
        if b < (k-a):
            ans += -1*(k-a-b)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    a, b, c, k = [int(x) for x in stdin.readline().rstrip().split()]
    if a >= k:
        print(k)
    elif a + b >= k:
        print(a)
    else:
        nokori = k - (a + b)
        print(a - nokori)

main()

Submission status: Accepted

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

A, B, C, K = mapint_inp()
# 1, 0, -1

ans = 0
if A >= K:
    print(K)
else:
    K -= A
    if B >= K:
        print(A)
    else:
        K -= B
        print(A+(-1)*K)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

left = 0
if k > a:
   ans = a
   left = k - a
else:
   print(k)
   exit()

if left > 0:
   if left > b:
      left = left - b
   else:
      print(ans)
      exit()

if left > 0:
   if left < c:
      print(ans - left)
   else:
      print(ans - c)

Submission status: Accepted

Solution code:
import numpy as np

ABCK=np.array(input().split(" "),dtype=np.int64)

A=ABCK[0]
B=ABCK[1]
C=ABCK[2]
K=ABCK[3]

total=0
cnt=1

if(A<=K):
    total+=1*A
    K=K-A
    if(B<=K):
        K=K-B
        if(0<K):
            total+=-1*K
        else:
            pass
    else:
        pass
else:
    total+=1*K

print(total)

Submission status: Accepted

Solution code:
A,B,C,K = map(int,input().split())
ans = 0

if A >= K:
    ans = 1*K
else:
    ans += 1*A
    K = K - A
    if B >= K:
        ans += 0*K
    else:
        ans += 0*B
        K = K - B
        ans += (-1)*K
        
print(ans)

Submission status: Accepted

Solution code:
import sys

A,B,C,K = map(int, input().split())

left=K
sum=0
if K<=A:
    print(K)
    sys.exit()
else:
    sum+=A
    left-=A
    if left<=B:
        print(sum)
        sys.exit()
    else:
        left-=B
        sum-=left
        print(sum)
        sys.exit()

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

if K <= A:
  max = K

if A < K <= A + B:
  max = A

if A + B < K:
  max = A - (K - A - B)

print(max)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

a,b,c,k = map(int,readline().split())
n = a+b+c
if k <= a:
    print(k)
elif k <= a+b:
    print(a)
else:
    print(a-c+(n-k))

Submission status: Accepted

Solution code:
# B
A, B, C, K = map(int, input().split())
ans = 0
if (K <= A):
    ans = K
else:
    ans += A
    K -= A
    if (K > B):
        K -= B
        ans -= 1 * K
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(A: int, B: int, C: int, K: int):
    if K<=A:
        print(K)
        return
    elif K<=A+B:
        print(A)
        return
    elif K<=A+B+C:
        print(A-(K-A-B))
        return
    else:
        print(A-C)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,k = (int(x) for x in input().split())
count = 0
if a >= k:
    count += k;
    k = 0
else:
    count += a
    k -= a
# print(count)
if b >= k:
    count += 0;
    k = 0
else:
    count += 0
    k -= b
# print(count)

if c >= k:
    count -= k;
    k = 0
else:
    count -= a
    k -= a
print(count)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split(" "))

if K <= A:
    print(1*K)
elif K <= B:
    print(1*A + 0*(K-A))
else:
    print(1*A + 0*B + (-1)*(K-A-B))

Submission status: Accepted

Solution code:
A, B, C, K = map(int,input().split())

def calculate(a,b,c,k):
    if k<= a+b:
        if k <= a:
            print(k)
        else:
            print(a)
    else:
        print(a - (k - (a+b)))

calculate(A,B,C,K)

Submission status: Accepted

Solution code:
def main():
    a, b, c, k = input_list()

    if a == k:
        print(a)
        exit()

    if a > k:
        print(k)
        exit()

    ans = a
    nokori = k - a
    if nokori <= b:
        print(ans)
    else:
        nokori -= b
        ans += nokori * -1
        print(ans)

def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
ans=0
if k<=a:
    ans=k*1
elif k<=b:
    ans=a*1
else:
    ans=a*1-(k-a-b)*1
print(ans)

Submission status: Accepted

Solution code:
A, B, C, K = list(map(int,input().split()))

if K <= A:
	max = K
elif A < K and K <= A+B:
	max = A
else:
	max = A-(K-(A+B))
	
print(max)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c,k = readInts()
    if a >= k:
        print(k)
    else:
        if a + b >= k:
            print(a)
        else:
            print(a - (k - (a + b)))
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
A, B, C, K = list(map(int, input().split()))
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(2 * A + B - K)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

if k-a-b <= 0:
  x =0
else:
  x = k-a-b
  


ans = min(a, k)*1 - x
print(ans)

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())

if a > k:
    print(k)
elif a + b > k:
    print(a)
else:
    sum = a - (k - a -b)
    print(sum)

Submission status: Accepted

Solution code:
#200510B
A, B, C, K = map(int, input().split())
ans = 0
if A >= K:
    ans = K
elif A + B >= K:
    ans = A
else:
    ans = 2*A + B - K
print(ans)

Submission status: Accepted

Solution code:
a, b, c, k = map(int, input().split())

print(min(a, k) - max(0, (k - a - b)))

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
if k<=a:
    print(k)
elif k<=(a+b):
    print(a)
elif k<=(a+b+c):
    print(a-(k-a-b))

Submission status: Accepted

Solution code:
a,b,c,k = map(int,input().split())
ans=min(k,a)-max(min(k-a-b,c),0)
print(ans)

Submission status: Accepted

Solution code:
A,B,C,K = map(int, input().split())

if A >= K:
	print(K)
elif A+B >= K:
	print(A)
else:
	print(A-(K-(A+B)))

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())

if a>=k:
    d=k
elif a<k and a+b>=k:
    d=a
elif a+b<k:
    d=a-(k-a-b)

print(d)

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

if K <= A:
    print(K)
elif K <= (A + B):
    print(A)
else:
    print(A - (K - A - B))

Submission status: Accepted

Solution code:
A, B, C, K = map(int, input().split())

result = 0

if K <= A:
    result = K
elif K <= A + B:
    result = A
else:
    result = A - (K - A - B)

print(result)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    A, B, C, K=MI() 

    if K<=A:
        print(K)
    elif K>A and K<= A+B:
        print(A)
    elif K >= A + B:
        print(A -(K-A-B))

    


if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
def main():
    A,B,C,K  = map(int, input().split()) 
    sums = 0

    if A<K:
        sums += A
        K = K-A
    else:
        sums=K
        print(sums)
        return
    if B<K:
        K = K-B
    else:
        print(sums)
        return
    if C<K:
        sums -=C
        print(sums)
        return
    else:
        sums -=K
        print(sums)
        return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c , k = [int(x) for x in input().split()]
aa = min(a, k)
bb = min(b, k - aa)
cc = min(c, k - aa - bb)
maxs = aa * 1 + bb * 0 + cc * -1
print(maxs)

Submission status: Accepted

Solution code:
a,b,c,k=map(int,input().split())
if a>=k:
  print(k)
elif a<k and (a+b)>=k:
  print(a)
else:
  print(a-(k-a-b))

Submission status: Accepted

Solution code:
nums = [int(e) for e in input().split()]
a = nums[0]
b = nums[1]
c = nums[2]
k = nums[3]
total = 0

if a > k:
    total = 1 * k
elif b > (k-a):
    total = 1 * a
else:
    total = 1 * a + (-1) * (k-a-b)

print(total)